showModalBottomSheet does not provide any styling or decorations. I want to create something like the Google Tasks bottomsheet.
i have this code and work well for me. please check it and let me know you'r opinion.
showBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
context: context,
builder: (context) => Container(
height: 250,
child: new Container(
decoration: new BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(20.0),
topRight: const Radius.circular(20.0))),
child: new Center(
child: new Text("This is a modal sheet"),
)),
))
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
clipBehavior: Clip.antiAliasWithSaveLayer,
)
Just answered a related question
You can add corners to your bottomSheet
and expand your bottomSheet
according to content present inside it (not restricted to half size of screen)
check out the answer here
https://stackoverflow.com/a/59541927/9236994
This is the modalBottomSheet function needed.
void _modalBottomSheetMenu(){
showModalBottomSheet(
context: context,
builder: (builder){
return new Container(
height: 350.0,
color: Colors.transparent, //could change this to Color(0xFF737373),
//so you don't have to change MaterialApp canvasColor
child: new Container(
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0))),
child: new Center(
child: new Text("This is a modal sheet"),
)),
);
}
);
}
Also the most important part of this working properly is, in MaterialApp set canvasColor to transparent like the one shown below.
return new MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Tasks',
theme: new ThemeData(
primarySwatch: Colors.teal,
canvasColor: Colors.transparent,
),
home: new TasksHomePage(),
);
}
I have tested the code and it works fine as I was also making a clone of the Google Tasks app which will be opensourced in my github.
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
builder: (ctx) {
return Container(
decoration: BoxDecoration(
color: Colors.green, // or some other color
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0)
)
);
});
You can now do it using the default showModalBottomSheet
method that now supports adding a ShapeBorder
and also backgroundColor
!
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
backgroundColor: Colors.white,
...
);
Instead of overriding the entire theme of the app (which caused problems in various parts of my app) as suggested by other answers, I decided to take a look at the implementation for showModalBottomSheet
and find the problem myself. Turns out that all that was needed was wrapping the main code for the modal in a Theme
widget that contains the canvasColor: Colors.transparent
trick. I also made it easier to customize the radius and also the color of the modal itself.
You can use either the package on pub or a gist containing the same code. Don't forget to import the proper package/file.
showRoundedModalBottomSheet(
context: context,
radius: 20.0, // This is the default
color: Colors.white, // Also default
builder: (context) => ???,
);