未格式化的 BottomNavigationBar 颤振

ayowhatthedogdoin

我创建了一个简单的底部导航栏,(我的代码如下)...

bottomNavigationBar: BottomNavigationBar(
    backgroundColor: COLOR_WHITE,
    items: const [
        BottomNavigationBarItem(
        icon: Icon(Icons.account_circle_rounded),
        label: 'Profile',
        ),
        BottomNavigationBarItem(
        label: 'something', icon: Icon(Icons.star)),
   ],
)

在此处输入图像描述

...但后来我真的很想点击图标,所以我尝试为其 onPressed() 方法添加一个图标按钮。

bottomNavigationBar: BottomNavigationBar(
     backgroundColor: COLOR_WHITE,
     items: [
          BottomNavigationBarItem(
              icon: IconButton(
                    icon: const Icon(Icons.account_circle_rounded),
                    onPressed: () {
                      Navigator.of(context).pushReplacement(
                      MaterialPageRoute(builder: (context) => ProfileScreen(userID :widget.userID)),
                    );
                    },
                  ), 
              label: "Profile"
                ),

          BottomNavigationBarItem(
              label: 'something', icon: Icon(Icons.star)),
            ],
),

在此处输入图像描述

它变得很丑陋,我希望周围的填充和大小保持不变,但是由于我没有添加代码来更改这些功能,所以我不明白为什么会发生这种情况。有人可以帮我解决吗?谢谢!!

汤姆·西特

BottomNavigationBar 有一个onTap方法可用于触发回调,因此您不需要 IconButton。onTap为您提供所点击项目的索引,以便您可以将其映射到适当的页面。您还可以更新 上的currentIndex属性BottomNavigatorBar以突出显示相应的项目。

请参阅 BottomNavigationBar 的文档以获取一个很好的示例:https ://api.flutter.dev/flutter/material/BottomNavigationBar-class.html

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章