Flutter沉浸式透明状态栏-flutter自定义凸起BottomAppBar导航
warning:
这篇文章距离上次修改已过182天,其中的内容可能已经有所变动。
在Flutter中,如果你想要实现沉浸式的透明状态栏,并且创建一个凸起的BottomAppBar
导航栏,你可以使用AnnotatedRegion
来设置状态栏为透明并且使用Material
控件的elevation
属性来创建凸起的效果。以下是一个简单的示例代码:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: Container(
color: Colors.deepOrange,
// 这里是你的内容,可以是其他你想展示的widget
child: Center(
child: Text(
'Hello, World!',
style: TextStyle(color: Colors.white, fontSize: 24),
),
),
),
),
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
child: Container(
height: 50.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
IconButton(icon: Icon(Icons.home), onPressed: () {}),
IconButton(icon: Icon(Icons.mail), onPressed: () {}),
IconButton(icon: Icon(Icons.message), onPressed: () {}),
],
),
),
),
);
}
}
在这个例子中,HomePage
使用AnnotatedRegion
来设置状态栏为SystemUiOverlayStyle.light
,这样状态栏就会是透明的。BottomAppBar
有一个圆形凹槽,这是通过shape
属性设置的,其中CircularNotchedRectangle
是Flutter提供的用于创建凸起效果的类。这个BottomAppBar
包含了三个IconButton
,用于导航。
评论已关闭