I was building a flutter app. In there I made a SliverAppBar:
child: NestedScrollView (
headerSliverBuilder: (BuildContext context, i) {
return <Widget> [
SliverAppBar (
backgroundColor: Colors.black,
expandedHeight: 150.0,
)
];
},
I made the height to 150.0 px. But I realized that this size will change in different devices. How can I make the size take up 40% of the screen in every device?
You can use the BuildContext context
with a MediaQuery
to find out the current devices screen size. For example:
var width = MediaQuery.of(context).size.width * 0.4; // set width to 40% of the screen width
var height = MediaQuery.of(context).size.height * 0.4; // set height to 40% of the screen height
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With