当我在iOS上运行Ffltter应用程序时,我的底部导航格式错误.它似乎在漂浮:

enter image description here

我的脚手架是这样的:

Scaffold(
  appBar: getAppbar(),
  drawer: getMainDrawer(context),
  floatingActionButton: ...,
  floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  body: SafeArea(
    top: false,
    bottom: false,
    child: _widgetOptions.elementAt(_selectedIndex),
  ),
  extendBody: true,
  bottomNavigationBar: buildBottomNavigationBar())

我的底部导航如下所示:

Widget buildBottomNavigationBar() {
  return BottomAppBar(
    key: const Key('bottomAppBar'),
    shape: const CircularNotchedRectangle(),
    elevation: 4,
    notchMargin: 8,
    clipBehavior: Clip.antiAlias,
    child: BottomNavigationBar(
      showUnselectedLabels: false,
      showSelectedLabels: false,
      items: const <BottomNavigationBarItem>[
        BottomNavigationBarItem(
          icon: FaIcon(FontAwesomeIcons.dumbbell),
          label: 'Sets',
        ),
        BottomNavigationBarItem(
          icon: FaIcon(FontAwesomeIcons.calendar),
          label: 'Timeline',
        ),
      ],
      currentIndex: _selectedIndex,
      onTap: _onItemTapped,
    ),
  );
}

请注意,底部导航在Android上看起来很好.有人知道iOS上出现这种情况的原因吗?

推荐答案

事实证明,@Ajil O终究是正确的.这个漏洞确实是由缺口效应引起的.要解决此问题,必须将所有位置的标高设置为0.

这段代码现在可以在iOS和Android上运行:

Widget buildBottomNavigationBar() {
  return BottomAppBar(
    key: const Key('bottomAppBar'),
    shape: const CircularNotchedRectangle(),
    // Note: elevation has to be zero
    elevation: 0,
    notchMargin: 8,
    clipBehavior: Clip.antiAlias,
    child: BottomNavigationBar(
      showUnselectedLabels: false,
      // Note: elevation has to be zero
      elevation: 0,
      showSelectedLabels: false,
      items: const <BottomNavigationBarItem>[
        BottomNavigationBarItem(
          icon: FaIcon(FontAwesomeIcons.dumbbell),
          label: 'Sets',
        ),
        BottomNavigationBarItem(
          icon: FaIcon(FontAwesomeIcons.calendar),
          label: 'Timeline',
        ),
      ],
      currentIndex: _selectedIndex,
      onTap: _onItemTapped,
    ),
  );

Ios相关问答推荐

在带有可编码的SWIFT5中,可以轻松处理以美元符号开头的JSON密钥,例如$DATE";

在某些情况下,UIHostingController在自动调整时不能调整大小

UITableViewCell编程约束问题

Flutter 应用程序中带有Firebase的GoogleService-Info.plist中缺少CLIENT_ID、REVERSED_CLIENT_ID和ANDROID_CLIENT-ID

Flutter Aging Person 自定义小部件

CarPlay:现在播放alert 可能吗?

为什么 Swift 不在启动的同一线程上恢复异步函数?

Swift Combine 防止初始值触发接收器并同时防止重复?

用溢出的长文本对齐 Flutter 中的行和列

Swift 图表:.chartYScale 似乎只适用于 100 的增量?

按钮在 SwiftUI 中没有采用给定的高度和宽度

将 SwiftUI 与 @AppStorage 和动态函数调用一起使用

SignalR 永远不会在 iOS 上使用 Xamarin Forms 启动

如何以编程方式调用视图控制器?

ios 崩溃 EXC_BAD_ACCESS KERN_INVALID_ADDRESS

SwiftUI 视图 - viewDidLoad()?

当键盘出现在 iOS 中时,将 UIView 上移

UIButton 事件.有什么不同?

如何动态计算 UILabel 高度?

如何以编程方式切换 UISegmentedControl?