我实现了一个导航栏,但是现在没有点击的其他标签没有显示。有人能告诉我为什么吗?在此处输入图像描述我的代码:home.dart:import'package:fi...
我实现了一个导航栏,但是现在没有点击的其他标签没有显示。有人能告诉我为什么吗?
在此处输入图片描述 我的代码:
主页.dart:
import 'package:fiips/MyBottomNavigationBar.dart';
import 'package:flutter/material.dart';
class Home extends StatelessWidget {
const Home({super.key});
final int test = 5;
@override
Widget build(BuildContext context) {
return const Scaffold(
bottomNavigationBar: MyBottomNavigationBar()
);
}
}
我的底部导航栏:
import 'package:flutter/material.dart';
class MyBottomNavigationBar extends StatelessWidget {
const MyBottomNavigationBar({super.key});
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
currentIndex: 0,
fixedColor: Colors.white,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home, color: Colors.white),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.devices, color: Colors.white),
label: 'Devices',
),
BottomNavigationBarItem(
icon: Icon(Icons.notifications, color: Colors.white),
label: 'Notifications',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings, color: Colors.white),
label: 'Settings',
),
],
//currentIndex: 1,
//onTap: _onItemTapped,
);
}
}
如果您希望其他标签像第一个标签一样显示,请使用
类型:BottomNavigationBarType.fixed
在你的 BottomNavigationBar
完整示例:
BottomNavigationBar(
currentIndex: 0,
type: BottomNavigationBarType.fixed,
fixedColor: Colors.white,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home, color: Colors.white),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.devices, color: Colors.white),
label: 'Devices',
),
BottomNavigationBarItem(
icon: Icon(Icons.notifications, color: Colors.white),
label: 'Notifications',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings, color: Colors.white),
label: 'Settings',
),
],
//currentIndex: 1,
//onTap: _onItemTapped,
)