【问题标题】:Flutter BottomNavigationBar with more than 3 items automatically applies padding depending on the selected itemFlutter BottomNavigationBar 超过 3 个项目会根据所选项目自动应用填充
【发布时间】:2021-01-01 14:13:40
【问题描述】:

在我的应用程序中有一个 BottomNavigationBar,目前有 4 个项目。它的代码如下:

  bottomNavigationBar: BottomNavigationBar(
    items: [
      BottomNavigationBarItem(icon: Icon(Icons.home), label: "Startseite"),
      BottomNavigationBarItem(icon: Icon(Icons.star), label: "Favoriten"),
      BottomNavigationBarItem(icon: Icon(Icons.casino), label: "Quiz"),
      BottomNavigationBarItem(icon: Icon(Icons.map), label: "Karte"),
    ],
    currentIndex: _selectedIndex,
    unselectedItemColor: Colors.grey,
    showUnselectedLabels: true,
    selectedItemColor: Colors.blue,
    onTap: _onItemTapped,
  ),

_selectedIndex 只是一个整数。 _onItemTapped 函数:

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
    setState(() {
      if (index == 0) {
        SwipePage();
      } else if (index == 1) {
        DatabaseProvider.db.queryDb();
        Navigator.of(context).push(
          toFavouritesPage(),
        );
      } else if (index == 2) {
        Navigator.of(context).push(
          toQuizPage(),
        );
      } else if (index == 3) {
        Navigator.of(context).push(
          toMapsPage(),
        );
      }
    });
  }

有 3 个项目,它看起来像这样(所有内容均匀分布):

有 4 个项目看起来像这样(我不明白这个填充来自哪里):

如何去除填充以使所有内容保持均匀分布?

【问题讨论】:

    标签: flutter dart flutter-layout flutter-widget


    【解决方案1】:

    将 bottomNavigationBarType: 设置为固定。默认情况下,在四个或更多项目上,它正在发生变化。这将突出显示所选项目,使其更加独特。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多