【问题标题】:How to center align bottom navigation bar items in iphones that have default safe area in flutter?如何在具有默认安全区域的 iphone 中居中对齐底部导航栏项目?
【发布时间】:2021-10-30 15:54:53
【问题描述】:

我发现在某些具有默认安全区域的 iphone 中,底部导航栏项目未正确居中对齐。例如:在此图片中,项目未正确居中对齐。如何正确对齐这些项目?

但是这里的项目是正确对齐的。

.

我的代码是:

Scaffold(
          body: _children[watch(tabviewProvider).currentBottomNavIndex],
          bottomNavigationBar: Container(
            height: watch(tabviewProvider).isBottomTabbarHide ? 0.0 : (SizeConfig.blockSizeVertical)*10, //94
            decoration: BoxDecoration(
              color: Colors.orange,//Todo:remove
              boxShadow: <BoxShadow>[
                BoxShadow(
                  color: Color(0xffE5E5E5),
                  blurRadius: 5,
                ),
              ],
            ),
            child: Align(
              alignment: Alignment.center,
              child: BottomNavigationBar(
                backgroundColor: Colors.grey, //Todo:remove
               // backgroundColor: Color(0xffF7F3ED),
                selectedFontSize: 0,
                showSelectedLabels: false,
                showUnselectedLabels: false,
                type: BottomNavigationBarType.fixed,
                key: bottomNavGlobalKey,
                onTap: onTabTapped,
                currentIndex: watch(tabviewProvider).currentBottomNavIndex,
                items: [
                  BottomNavigationBarItem(
                    activeIcon: BottmNavTabButton(
                      isActive: true,
                      imgPath: 'assets/icons/icon_timeline_pink.svg',
                      lableText: 'A',
                    ),
                    label: '',
                    icon: BottmNavTabButton(
                      isActive: false,
                      imgPath: 'assets/icons/icon_timeline_gray.svg',
                      lableText: 'A',
                    ),
                  ),
                  BottomNavigationBarItem(
                    activeIcon: BottmNavTabButton(
                      isActive: true,
                      imgPath: 'assets/icons/icon_knowledge_pink.svg',
                      lableText: 'B',
                    ),
                    label: '',
                    icon: BottmNavTabButton(
                      isActive: false,
                      imgPath: 'assets/icons/icon_knowledge_gray.svg',
                      lableText: 'B',
                    ),
                  ),

                  BottomNavigationBarItem(
                    activeIcon: BottmNavTabButton(
                      isActive: true,
                      imgPath: 'assets/icons/icon_offer_pink.svg',
                      lableText: 'C',
                    ),
                    label: '',
                    icon: BottmNavTabButton(
                      isActive: false,
                      imgPath: 'assets/icons/icon_offer_gray.svg',
                      lableText: 'C',
                    ),
                  )
                ],
              ),
            ),
          ),
        );

【问题讨论】:

    标签: flutter navigationbar flutter-ios


    【解决方案1】:

    为了实现您想要的行为,我会将 SafeArea 底部属性设置为 false 并用 Padding() 包装您的每个图标

    SafeArea(
      bottom: false,
      child: …,
    )
    
    Padding(
      top: value, 
      bottom: value, 
      child : BottmNavTabButton(…),
    )
    

    【讨论】:

    • 我试过了,好像没有解决问题。
    • 它不会删除您在 iOS 设备上需要的 SafeArea,但它允许您设置一些所需的顶部填充以使其看起来更好 - 如果您查看 facebook 或 Apple Store 应用程序,底部导航栏看起来像这样
    猜你喜欢
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多