how to set showModalBottomSheet to full height

后端 未结 5 1888
星月不相逢
星月不相逢 2020-12-14 02:01

i use showRoundedModalBottomSheet, how to adjust this modal height till below the appbar?

相关标签:
5条回答
  • 2020-12-14 02:03

    What worked for me was returning the modal's content wrapped in a DraggableScrollableSheet:

    showModalBottomSheet(
      backgroundColor: Colors.transparent,
      context: context,
      isScrollControlled: true,
      isDismissible: true,
      builder: (BuildContext context) {
        return DraggableScrollableSheet(
          initialChildSize: 0.75, //set this as you want
          maxChildSize: 0.75, //set this as you want
          minChildSize: 0.75, //set this as you want
          expand: true,
          builder: (context, scrollController) {
            return Container(...); //whatever you're returning, does not have to be a Container
          }
        );
      }
    )
    
    0 讨论(0)
  • 2020-12-14 02:06

    I guess the easiest way is:

    showModalBottomSheet(
          isScrollControlled: true,
          context: context,
          builder: (context) => Wrap(children: [YourSheetWidget()]),
        );
    
    0 讨论(0)
  • 2020-12-14 02:15

    If you call showModalBottomSheet() with isScrollControlled: true, then the dialog will be allowed to occupy the whole height.

    To adjust the height to the content, you can proceed as usually, for example, using Container and Wrap widgets.

    Example:

    final items = <Widget>[
      ListTile(
        leading: Icon(Icons.photo_camera),
        title: Text('Camera'),
        onTap: () {},
      ),
      ListTile(
        leading: Icon(Icons.photo_library),
        title: Text('Select'),
        onTap: () {},
      ),
      ListTile(
        leading: Icon(Icons.delete),
        title: Text('Delete'),
        onTap: () {},
      ),
      Divider(),
      if (true)
        ListTile(
          title: Text('Cancel'),
          onTap: () {},
        ),
    ];
    
    showModalBottomSheet(
      context: context,
      builder: (BuildContext _) {
        return Container(
          child: Wrap(
            children: items,
          ),
        );
      },
      isScrollControlled: true,
    );
    
    0 讨论(0)
  • 2020-12-14 02:17

    [Update]

    In showModalBottomSheet(...) set the property isScrollControlled:true.

    It will make bottomSheet to full height.


    [Original answer]

    You can Implement the FullScreenDialog instead.

    Flutter Gallery app has an example of FullScreenDialog

    You can open your Dialog using below code:

    Navigator.of(context).push(new MaterialPageRoute<Null>(
          builder: (BuildContext context) {
            return Dialog();
          },
        fullscreenDialog: true
      ));
    

    Check this blog post too for more:

    Hope it will help you.

    0 讨论(0)
  • 2020-12-14 02:23
    1. You open class BottomSheet in library of flutter and change maxHeight

    from

    BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
    return BoxConstraints(
      minWidth: constraints.maxWidth,
      maxWidth: constraints.maxWidth,
      minHeight: 0.0,
      maxHeight: constraints.maxHeight * 9.0 / 16.0
    );}
    

    to

    BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
    return BoxConstraints(
      minWidth: constraints.maxWidth,
      maxWidth: constraints.maxWidth,
      minHeight: 0.0,
      maxHeight: constraints.maxHeight
    );}
    
    1. You can create a new class with other name and copy source code from class BottomSheet and change maxHeight
    0 讨论(0)
提交回复
热议问题