Ext*_*tra 5 user-interface frontend dart flutter
我正在构建一个颤振应用程序。在那里我做了一个 SliverAppBar:
child: NestedScrollView (
headerSliverBuilder: (BuildContext context, i) {
return <Widget> [
SliverAppBar (
backgroundColor: Colors.black,
expandedHeight: 150.0,
)
];
},
Run Code Online (Sandbox Code Playgroud)
我将高度设置为 150.0 像素。但我意识到这个大小会在不同的设备中发生变化。如何让每个设备的尺寸都占屏幕的 40%?
您可以使用BuildContext context
和 aMediaQuery
来查找当前设备的屏幕尺寸。例如:
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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4075 次 |
最近记录: |