我正在构建一个颤振应用程序。在那里,我做了一个SliverAppBar:
child: NestedScrollView (
headerSliverBuilder: (BuildContext context, i) {
return <Widget> [
SliverAppBar (
backgroundColor: Colors.black,
expandedHeight: 150.0,
)
];
},
我把高度提高到 150.0 像素。但我意识到这个尺寸在不同的设备中会发生变化。如何使尺寸在每个设备中占据屏幕的 40%?
您可以将BuildContext context
与MediaQuery
一起使用,以找出当前的设备屏幕尺寸。例如:
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