3.1 appBar(应用顶栏)
-
类型:
AppBar
-
功能:显示页面标题、导航按钮和操作项
-
代码示例:
appBar: AppBar(
title: Text('首页'),
actions: [
IconButton(icon: Icon(Icons.search), onPressed: () {}),
IconButton(icon: Icon(Icons.settings), onPressed: () {})
],
)
3.2 body(主体内容)
-
类型:
Widget
-
功能:承载页面主要内容区域
-
最佳实践:通常使用
Container
、ListView
或Column
等布局组件包裹内容
3.3 floatingActionButton(悬浮按钮)
-
类型:
FloatingActionButton
-
功能:执行主要操作(如新建、发布等)
-
定位控制:通过
floatingActionButtonLocation
调整位置
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
tooltip: '新建',
)
3.4 drawer(左侧抽屉)
-
类型:
Drawer
-
功能:侧滑显示导航菜单
-
打开方式:手指从左侧边缘右滑或点击 AppBar 导航图标
drawer: Drawer(
child: ListView(
children: [
ListTile(title: Text('菜单项1'), onTap: () {}),
ListTile(title: Text('菜单项2'), onTap: () {})
],
),
)
3.5 bottomNavigationBar(底部导航栏)
-
类型:
BottomNavigationBar
-
功能:实现多页面切换导航
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
BottomNavigationBarItem(icon: Icon(Icons.person), label: '我的')
],
currentIndex: _selectedIndex,
onTap: (index) => setState(() => _selectedIndex = index),
)