1

I need an AlertDialog with minHeight of 50. It contains a ListView. If the ListView exceeds the screen it should become scrollable. But I can't scroll for some reason. Can anyone explain to me why it's not working :)

 AlertDialog(
  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
  title: ... ,
  content: ConstrainedBox(
    constraints: new BoxConstraints(
      minHeight: 50,
    ),
    child: Column(
      children: <Widget>[
        Row(...),
        Container(
          child:  ListView.builder(
            shrinkWrap: true,
            itemCount: list.length,
            itemBuilder: (context, index) {
              return GestureDetector(
                onTap: () => _onTap(list[index]),
                child: Row(
                  children: <Widget>[
                    Flexible(
                      flex: 1,
                      child: Checkbox(...),
                    ), 
                    Flexible(
                      flex: 3,
                      child: Text(list[index]),)
                  ],
                )
              );
            },
          )
        )
      ],
    ),
   ),
  actions: <Widget>[
    MaterialButton(
      minWidth:100,
      child: Text('Cancel'),
      onPressed: (){
        Navigator.of(context).pop();
      }
    ),
    MaterialButton(
      minWidth:100,
      elevation: 5.0,
      color: Theme.of(context).accentColor,
      child: Text('Save', style: TextStyle(color: Color(0xFFF6F5F5))),
      onPressed: (){

      }
    )
  ],
);
Frederik
  • 1,221
  • 2
  • 13
  • 22

1 Answers1

1

Add mainAxisSize: MainAxisSize.min to your Column. Without it, your Column is at infinite height and contains all Listview items. That's why it does not scroll.

Hoàn Lê
  • 127
  • 1
  • 4
  • Weird. I just tested a similar code (but of course simpler than yours) and has no issue. Other part of your code might cause the problem then – Hoàn Lê Feb 16 '20 at 19:10
  • yes the problem is probably occurring somewhere else. I'll test it out at the weekend. – Frederik Feb 25 '20 at 19:48