要将Flutter App中的页面设置为全屏显示,可以在Scaffold的构造函数中添加如下代码:
Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/bg_image.png"),
fit: BoxFit.cover,
),
),
child: Center(
child: Text(
"This is a full-screen page",
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
);
其中,Container的decoration属性可以设置图片框。在本例中,我们定义了一张名为"bg_image.png"的背景图片,在Container的decoration中引入,并将其铺满整个容器。
可以使用如下代码在Flutter App中实现将页面设置为全屏显示:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Full-Screen Page',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/bg_image.png"),
fit: BoxFit.cover,
),
),
child: Center(
child: Text(
"This is a full-screen page",
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
),
);
}
}