How to show margin on left, right and bottom of showModalBottomSheet?

Viewed 4154

For the showModalBottomSheet i want to display margin around it. Mainly left and right. SO that it will look separated from the screen sides. How to achieve that. Also If i want to provide margin at the bottom, how to achieve that. Is there any other widget which provides the similar behavior as modalbottomsheet but with the margins?

3 Answers

with flutter you can use any widget Here is an example

_showModalBottomSheetCustom(BuildContext context) {
  showModalBottomSheet<void>(
    context: context,
    builder: (BuildContext context) {
      return Container(
         margin: EdgeInsets.symmetric(horizontal: 3),
         child: ...
      );
    }
  );
}

EDIT

The margin is between the modal and the child, to "see" it, insert the transparent color on the modal

_showModalBottomSheetCustom(BuildContext context) {
  showModalBottomSheet<void>(
    context: context,
    backgroundColor: Colors.transparent,
    builder: (BuildContext context) {
      return Container(
         color: Colors.white,
         margin: EdgeInsets.symmetric(horizontal: 30),
         child: ...
      );
    }
  );
}

You can try this,It worked for me.

Get.bottomSheet(
    new Container(
    //height: 150,
    color: Colors.white,
    margin: EdgeInsets.all(10),
    child: Wrap(
    children: [
        ListTile(
        title: Text('title',
            textAlign: TextAlign.center),
        ),
        Divider(),
        ListTile(
        title: Text('title',
            textAlign: TextAlign.center),
        ),
        Divider(thickness: 9),
        ListTile(
        title: Text('title',
            textAlign: TextAlign.center),
        shape: RoundedRectangleBorder(
            borderRadius:
                BorderRadius.horizontal()),
        ),
    ],
    ),
));

The result:

Result]

The simplest way to do is using constraints like here

 showModalBottomSheet(        
        context: context,
        constraints: BoxConstraints(
          maxWidth: MediaQuery.of(context).size.width - 40, // here increase or decrease in width
        ),
        builder: (context) {
          return BottomSheetContent();
        });
Related