长沙网站建设哪家公司好,快速建设企业门户网站,做摄影网站,整站seo排名外包常用基本属性
属性名含义是否必须items底部导航栏的子项List是currentIndex当前显示索引否onTap底部导航栏的点击事件#xff0c; Function(int)否type底部导航栏类型#xff0c;定义 [BottomNavigationBar] 的布局和行为否selectedItemColor选中项图标和label的颜色否unsel…常用基本属性
属性名含义是否必须items底部导航栏的子项List是currentIndex当前显示索引否onTap底部导航栏的点击事件 Function(int)否type底部导航栏类型定义 [BottomNavigationBar] 的布局和行为否selectedItemColor选中项图标和label的颜色否unselectedItemColor未选中项图标和label的颜色否iconSize图标大小否backgroundColor底部导航栏背景色否showSelectedLabels是否显示选中项的label否showUnselectedLabels是否显示未选中项的label否selectedIconTheme选中项 图标的主题 设置否unselectedIconTheme选中项 图标的主题 设置否selectedFontSize选中项 文字大小 设置否unselectedFontSize未选中项 文字大小 设置否selectedLabelStyle选中项 文字样式 设置否unselectedLabelStyle未选中项 文字样式 设置否mouseCursor当鼠标指针进入或悬停在屏幕上时的光标否enableFeedback检测到的手势是否应提供声音和/或触觉反馈否
示例
效果一
当选中时图标文字变色未选中时不显示文字 bottomNavigationBar: BottomNavigationBar(selectedItemColor: Colors.red, // 选中时unselectedItemColor: Colors.black, // 未选中currentIndex: _currentIndex,onTap: (value) {setState(() {_currentIndex value;});},items: const [BottomNavigationBarItem(icon: Icon(Icons.home),label: Home,),// ...],),效果二
显示图标和文字选中变色
可设置type: BottomNavigationBarType.fixed固定或设置showUnselectedLabels: true bottomNavigationBar: BottomNavigationBar(selectedItemColor: Colors.red, // 选中时unselectedItemColor: Colors.black, // 未选中type: BottomNavigationBarType.fixed, // 固定currentIndex: _currentIndex,onTap: (value) {setState(() {_currentIndex value;});},items: const [BottomNavigationBarItem(icon: Icon(Icons.home),label: Home,),// ...],),效果三
显示图标和文字设置背景 type: BottomNavigationBarType.fixed必须与backgroundColor配合使用背景才生效 bottomNavigationBar: BottomNavigationBar(selectedItemColor: Colors.red, // 选中时unselectedItemColor: Colors.black, // 未选中type: BottomNavigationBarType.fixed, // 固定backgroundColor: Colors.amber, // 背景色currentIndex: _currentIndex,onTap: (value) {setState(() {_currentIndex value;});},items: const [BottomNavigationBarItem(icon: Icon(Icons.home),label: Home,),// ...],),完整示例
class PageWidget extends StatefulWidget {const PageWidget({super.key});overrideStatePageWidget createState() _PageWidgetState();
}class _PageWidgetState extends StatePageWidget {int _currentIndex 0;Widget _getPage(index) {final ListWidget _pages Widget[Container(color: Colors.red,child: ElevatedButton(onPressed: () {Navigator.pushNamed(context, /user-page);},child: const Text(User Page),)),Container(color: Colors.green,),Container(color: Colors.blue,),Container(color: Colors.yellow,),];return _pages[index];}overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text(Page Widget),),bottomNavigationBar: BottomNavigationBar(backgroundColor: Colors.amber,type: BottomNavigationBarType.fixed,// showSelectedLabels: true,// showUnselectedLabels: true,selectedItemColor: Colors.red,unselectedItemColor: Colors.black,currentIndex: _currentIndex,onTap: (value) {setState(() {_currentIndex value;});},items: const [BottomNavigationBarItem(icon: Icon(Icons.home),label: Home,),BottomNavigationBarItem(icon: Icon(Icons.business),label: Business,),BottomNavigationBarItem(icon: Icon(Icons.school),label: School,),BottomNavigationBarItem(icon: Icon(Icons.account_circle),label: User,),],),body: _getPage(_currentIndex),);}
}