Flutter: ListView in a SimpleDialog

后端 未结 9 1684
深忆病人
深忆病人 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:36

    SImply in the content we need to use a Container with fixed height and width. and the use ListView as a child of Container.

     scrollDialogFunction(){
            return showDialog(
                context: context,
                builder: (BuildContext context) {
                  return AlertDialog(
                    title: Text('List of Index'),
                    content: Container(
                      width: 350.0,
                      height: 250,// Change as per your requirement
                      child: ListView.builder(
                        itemCount: 150,
                        itemBuilder: (BuildContext context, int index) {
                          return ListTile(
                            title: Text(index.toString()),
                          );
                        },
                      ),
                    ),
                    actions: [Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Text("ok",style: TextStyle(fontSize: 18),),
                    )],
                  );
                });
          }
    

提交回复
热议问题