Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to constrain height of AlertDialog

Tags:

flutter

I show dialog with list inside it.

    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text(select_conference),
            content: ListView.separated(
              itemCount: selected.length,
              separatorBuilder: (context, index) => CommonDivider(),
              itemBuilder: (context, index) => ListTile(...),
            ),
          );
        });

But no matter how many elements is has - dialog fills all available height. Is there any solution to solve this without calculating height of list elements?

like image 391
Andrey Turkovsky Avatar asked Oct 09 '18 08:10

Andrey Turkovsky


People also ask

How do I make alert dialog fill 90% of screen size?

According to Android platform developer Dianne Hackborn in this discussion group post, Dialogs set their Window's top level layout width and height to WRAP_CONTENT . To make the Dialog bigger, you can set those parameters to MATCH_PARENT . Demo code: AlertDialog.

What is the difference between Dialog and AlertDialog?

AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .


1 Answers

Wrap your content with a Column and set mainAxisSize to MainAxisSize.min:

AlertDialog(
  content: Column(
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
      //your content
    ],
  ),
like image 151
Andrey Gordeev Avatar answered Nov 21 '22 08:11

Andrey Gordeev