How do you adjust the height and borderRadius of a BottomSheet in Flutter?

后端 未结 9 1364
野性不改
野性不改 2021-02-05 03:47

I\'m probably missing something obvious here, but my BottomSheet only takes up the bottom half the screen, even though the widgets in it take up more space. So now there is scro

9条回答
  •  轮回少年
    2021-02-05 04:13

    Use showBottomSheet instead of showModalBottomSheet

    Create global key and a listener

    final _scaffoldKey = new GlobalKey();
    VoidCallback _showPersBottomSheetCallBack;
    

    Write your method to show the sheet

      void _showBottomSheet() {
        setState(() {
          _showPersBottomSheetCallBack = null;
        });
    
        _scaffoldKey.currentState
            .showBottomSheet((context) {
          return new Container(
            height: MediaQuery.of(context).size.height-100.0,
            color: Colors.greenAccent,
            child: new Center(
              child: new Text("Hi BottomSheet"),
            ),
          );
        })
            .closed
            .whenComplete(() {
          if (mounted) {
            setState(() {
              _showPersBottomSheetCallBack = _showBottomSheet;
            });
          }
        });
      }
    

    initialize the listener

    void initState() {
        super.initState();
        _showPersBottomSheetCallBack = _showBottomSheet;
      }
    

    Call the method wherever you required

    new RaisedButton(
                      onPressed: _showPersBottomSheetCallBack,
                      child: new Text("Persistent"),
                    ),
    

    Hope it helps !

提交回复
热议问题