Flutter: ListView in a SimpleDialog

后端 未结 9 1676
深忆病人
深忆病人 2020-12-24 01:04

I want to show a SimpleDialog with ListView.builder in my Flutter app with this code:

showDialog(
  context: context,
  builder: (BuildContext context) {
           


        
9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 01:48

    Wraping the ListView in a Container and giving it a width: double.maxFinite, solves the problem with iOS/Android having trouble with ListView inside a dialog:

    showDialog(
       context: context,
       builder: (BuildContext context) {
          return AlertDialog(
             content: Container(
                width: double.maxFinite,
                child: ListView(
                   children: []
                ),
             ),
          );
       }
    );
    

    In the case of a ListView inside a Column that is inside an AlertDialog:

    showDialog(
       context: context,
       builder: (BuildContext context) {
          return AlertDialog(
             content: Container(
                width: double.maxFinite,
                child: Column(
                   mainAxisSize: MainAxisSize.min,
                   children: [
                      Expanded(
                         child: ListView(
                            shrinkWrap: true,
                            children: []
                         )
                      )
                   ]
                ),
             ),
          );
       }
    );
    

提交回复
热议问题