Flutter Bottom Sheet with Rounded Corners

To achieve a rounded bottom sheet appearance in a Flutter app, instead of repeating the phrases “showModalBottomSheet rounded corners,” you can set the background color of showModalBottomSheet to transparent and apply a clipper or rounded shape to it. Another solution is to use the “widget” function.


Solution:

The widget identified as

ClipRRect

is available for use.

void _showBottomSheet() {
    _scaffoldKey.currentState
        .showBottomSheet((BuildContext context) {
          final ThemeData themeData = Theme.of(context);
          return Theme(
            data: themeData.copyWith(canvasColor: Colors.orangeAccent,),
            child: DecoratedBox(
              decoration: BoxDecoration(color: Colors.transparent),
              child: ClipRRect(
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(22.0),
                    topRight: Radius.circular(22.0)),
                child:
                    new Column(mainAxisSize: MainAxisSize.min, children: [
                  BottomNavigationBar(
                    currentIndex: 0, // this will be set when a new tab is tapped
                    items: [
                      BottomNavigationBarItem(
                        icon: new Icon(Icons.share),
                        title: new Text('Share'),
                      ),
                      BottomNavigationBarItem(
                          icon: Icon(Icons.bookmark),
                          title: Text('Bookmark'))
                    ],
                    onTap: (index) {
                      if (index == 0) {
                        final RenderBox box = context.findRenderObject();
//                      Share.share('Hello this is a test',
//                          sharePositionOrigin:
//                          box.localToGlobal(Offset.zero) & box.size);
                      }
                    },
                  ),
                ]),
              ),
            ),
          );
        })
        .closed
        .whenComplete(() {
          if (mounted) {
//        setState(() { // re-enable the button
//          _showBottomSheetCallback = _showBottomSheet;
//          print ("_showBottomSheetCallback enable");
//        });
          }
        });
  }

Output:


Frequently Asked Questions