简体   繁体   English

Flutter:AlterDialog 中的 Listview 不可滚动

[英]Flutter: Listview in AlterDialog not scrollable

I need an AlertDialog with minHeight of 50 .我需要一个minHeight50AlertDialog It contains a ListView .它包含一个ListView If the ListView exceeds the screen it should become scrollable .如果ListView超出屏幕,它应该变成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: (){

      }
    )
  ],
);

Add mainAxisSize: MainAxisSize.min to your Column.将 mainAxisSize: MainAxisSize.min 添加到您的列中。 Without it, your Column is at infinite height and contains all Listview items.没有它,您的 Column 将处于无限高度并包含所有 Listview 项目。 That's why it does not scroll.这就是它不滚动的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM