[英]Flutter bottom navigation bar items not aligned
In my newspaper app, the left-most bottom navigation bar item is always showing up at a higher position than the other items, it is not aligned.在我的报纸应用程序中,最左边的底部导航栏项目总是以高于其他项目的 position 显示,它没有对齐。
You can see the bookmark
icon is not aligned with the others.您可以看到
bookmark
图标未与其他图标对齐。 In fact, if I put any other icon in the first position, that icon is showing up at a higher position.事实上,如果我将任何其他图标放在第一个 position 中,该图标将显示在更高的 position 中。 The problem is with that first item no matter what icon I add there.
无论我在那里添加什么图标,问题都在于第一个项目。
Code for the BottomNavigationBar
BottomNavigationBar
的代码
import 'package:flutter/material.dart';
import 'package:news_app/main.dart';
BottomNavigationBar getBottomNavBar(themeProvider, context, appbarScrollController, refresh) {
return BottomNavigationBar(
elevation: 3,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(
Icons.bookmark,
color: themeProvider.themeMode == ThemeMode.light ? Colors.black : Colors.white,
),
label: ""
),
BottomNavigationBarItem(
icon: Icon(
Icons.home_sharp,
color: themeProvider.themeMode == ThemeMode.light ? Colors.black : Colors.white,
),
label: ""
),
BottomNavigationBarItem(
icon: Icon(
Icons.subject,
color: themeProvider.themeMode == ThemeMode.light ? Colors.black : Colors.white,
),
label: ""
),
BottomNavigationBarItem(
icon: Icon(
Icons.video_collection,
color: themeProvider.themeMode == ThemeMode.light ? Colors.black : Colors.white,
),
label: ""
),
BottomNavigationBarItem(
icon: Icon(
Icons.more_horiz,
color: themeProvider.themeMode == ThemeMode.light ? Colors.black : Colors.white,
),
label: ""
),
],
onTap: (index) {
},
);
}
I kept all the labels
blank as I don't need them.我将所有
labels
都保留为空白,因为我不需要它们。 It appears the same in all the screens with this alignment problem.这个 alignment 问题在所有屏幕中看起来都是一样的。
According to the documentation:根据文档:
If type is not specified, then it's automatically set to BottomNavigationBarType.fixed when there are less than four items, and BottomNavigationBarType.shifting otherwise.
如果未指定 type,则当少于四个项目时,它会自动设置为 BottomNavigationBarType.fixed,否则将设置为 BottomNavigationBarType.shifting。
And since you have more than 3 items, the type changed to BottomNavigationBarType.shifting
which shifts the selected item slightly upward.并且由于您有 3 个以上的项目,因此类型更改为
BottomNavigationBarType.shifting
,它将所选项目略微向上移动。
Try this:尝试这个:
BottomNavigationBar(
type: BottomNavigationBarType.fixed,
...
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.