我是flutter的新手,我创建了一个BottomNavigationBar并向其中添加了一些包含flutter图标的BottomNavigationBarItem。
问题是,当我选择我的底部导航栏的一项时,该项目会移动其他图标。
这是我的应用程序的屏幕截图:
有没有办法阻止这种转变?
我的代码:
import 'package:flutter/material.dart';
class Navbar extends StatefulWidget {
const Navbar({ Key key }) : super(key: key);
@override
_NavbarState createState() => _NavbarState();
}
class _NavbarState extends State<Navbar> {
int index = 0;
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
iconSize: 30,
showSelectedLabels: false,
showUnselectedLabels: false,
selectedItemColor: Colors.blueGrey,
unselectedItemColor: Colors.black,
currentIndex: index,
onTap: (int selectedIndex) {
setState(() {
index = selectedIndex;
});
},
items: [
BottomNavigationBarItem(
icon: new Icon(
Icons.home,
),
title: new Text('Home'),
),
BottomNavigationBarItem(
icon: new Icon(
Icons.search,
),
title: new Text('Search'),
),
BottomNavigationBarItem(
icon: Icon(
Icons.add,
),
title: Text('Add')
),
BottomNavigationBarItem(
icon: Icon(
Icons.favorite,
),
title: Text('Add')
),
BottomNavigationBarItem(
icon: Icon(
Icons.account_circle,
),
title: Text('Account')
)
],
);
}
}
Run Code Online (Sandbox Code Playgroud)
Han*_*ner 11
您可以BottomNavigationBar通过在构造它时将其type参数设置为 来更改 的这种行为BottomNavigationBarType.fixed。
BottomNavigationBar(
...
type: BottomNavigationBarType.fixed,
...
}
Run Code Online (Sandbox Code Playgroud)
根据文档,默认值type是fixed四个或更少的项目,shifting如果有更多项目。
| 归档时间: |
|
| 查看次数: |
1443 次 |
| 最近记录: |