Flutter DraggableScrollableSheet doesn't show up by pressing button

前端 未结 3 877
日久生厌
日久生厌 2020-12-16 04:03

I want to use DraggableScrollableSheet widget on my application, when I use that like with below code, that can show without problem:

class Home         


        
3条回答
  •  长情又很酷
    2020-12-16 04:50

    If you want to show DraggableScrollableSheet as modal you can use material showModalBottomSheet method to wrap it. Your sheet will be shown as modal, and you do not have to include it in the widget tree. Please note that under the hood it's pushed as new Route to Navigator, with all its consequences.

    onPressed: (){
       showModalBottomSheet(
            context: context,
            isScrollControlled: true,
            isDismissible: true,
            expand: false,
            backgroundColor: Colors.transparent,
            builder: (context) =>
                DraggableScrollableSheet(
                  initialChildSize: 0.64,
                  minChildSize: 0.2,
                  maxChildSize: 1,
                  builder: (context, scrollController) {
                    return Container(
                      color: Colors.white,
                      child: ListView.builder(
                        controller: scrollController,
                        itemBuilder: (context, index) {
                            return ListTile(
                              title: Text('Item $index'),
                            );
                          },
                        itemCount: 20,
                      ),
                    );
                  },
                ),
          );
    }
    

提交回复
热议问题