简体   繁体   中英

flutter scrollable modal bottom sheet

Is there a way to make the ModalBottomSheet<\/code> with a fixed heigh i don't want it's height to expand when scrolling

showModalBottomSheet(
               context: context,
               isScrollControlled: true,
               backgroundColor: Colors.transparent,
                 builder: (context) => DraggableScrollableSheet(
                 builder: (BuildContext context,
               ScrollController scrollController) {
               return Container(
               color: Colors.blue[100],
               child: ListView.builder(
               controller: scrollController,
               itemCount: 25,
               itemBuilder:(BuildContext context,int index) {
                return ListTile(
                        title: Text('Item $index'));
               },
             ),
          );
        },
     ),
    );

You can remove the DraggableScrollableSheet. That widget allows for the height expanding I think. So after removing it, you can set a height on the container

final double height = 200;
showModalBottomSheet(
       context: context,
       backgroundColor: Colors.transparent,
       builder: (context){
       return Container(
         height: height,
         color: Colors.blue[100],
         child: ListView.builder(
         itemCount: 25,
         itemBuilder:(BuildContext context,int index) {
          return ListTile(
                  title: Text('Item $index'));
         }
      )
    );
  },
);

You can give your container that is currently blue coloured. a fixed height say height:200.. And you also need to remove draggable scrollable sheet builder from you bottom sheet.

"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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