Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bottom sheet with initial height half of screen and if it scroll then height is increase to full screen

I have a bottom sheet with below code in where i put a height 300.0 but I want increase height to full screen when user scroll ..how can i do that ..please

void _showBottomSheet() {
    setState(() {
      _showPersBottomSheetCallBack = null;
    });

    _scaffoldKey.currentState
        .showBottomSheet((context) {
      return new Container(
        height: 300.0,
        color: Colors.greenAccent,
        child: new Center(
          child: new Text("Hi BottomSheet"),
        ),
      );
    })
        .closed
        .whenComplete(() {
      if (mounted) {
        setState(() {
          _showPersBottomSheetCallBack = _showBottomSheet;
        });
      }
    });
  }
like image 711
Hitanshu Gogoi Avatar asked Aug 26 '18 16:08

Hitanshu Gogoi


People also ask

How do I open the bottom sheet in full screen on flutter?

The various approaches to solving the Flutter Full Screen Bottom Sheet problem are summarised in the following code. showModalBottomSheet( context: context, builder: (context) { return Column( mainAxisSize: MainAxisSize. min, children: <Widget>[ ListTile( leading: new Icon(Icons.

How do I make showModalBottomSheet full screen?

In showModalBottomSheet(...) set the property isScrollControlled:true . It will make bottomSheet to full height. You can Implement the FullScreenDialog instead.

How do I change the bottom sheet size in flutter?

We cannot change the height of the sheet and the max height will be half of the screen. But we can customize the code of the bottom sheet to give full height. First Create a new Dart File Called BottomSheetCustom and Copy the default bottom sheet code and Paste there.


2 Answers

If all you want is a full-screen bottom sheet (as @edmond demonstrates), you can now use isScrollControlled: true without having to maintain your own hacked version of BottomSheet.

Regardless, the question is about first loading the sheet to half height, with the ability to extend to full height on scroll. For that fine-grained control, you'll still want to use isScrollControlled: true, but also you can wrap the content of the modal sheet in DraggableScrollableSheet. This Github comment shows you how to do it, which I'm copying here for reference:

showModalBottomSheet(
  context: context,
  isScrollControlled: true,
  builder: (BuildContext context) {
    return DraggableScrollableSheet(
      initialChildSize: 0.5, // half screen on load
      maxChildSize: 1,       // full screen on scroll
      minChildSize: 0.25,
      builder: (BuildContext context, ScrollController scrollController) {
        return Container(
          color: Colors.white,
          child: ListView.builder(
            controller: scrollController,
            itemCount: 25,
            itemBuilder: (BuildContext context, int index) {
              return ListTile(title: Text('Item $index'));
            },
          ),
        );
      },
    );
  },
);
like image 107
stevenspiel Avatar answered Sep 22 '22 05:09

stevenspiel


The flutter package bottom sheet is not meant to occupy the full screen, though a little tweak can produce the behavior you expect. If you look at the BottomSheet constructor, you will find the following:

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

If you remove the 9.0/16.0 height constraint, the bottom sheet will occupy the full screen height.

like image 39
edmond Avatar answered Sep 20 '22 05:09

edmond