简体   繁体   中英

How do I get rid of extra BottomAppBar in Flutter?

I have extra footer BottomAppBar that I don't want to be there. I want the Bottom Navigation Bar to be nested within the Bottom App Bar because I still want to keep the notch for the Floating Action Button. The screenshot shows it clearly, as it is colored Red.

This is my code:

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(0),
        child: AppBar(
          elevation: 0,
          backgroundColor: Colors.transparent.withOpacity(0.4),
        ),
      ),
      extendBodyBehindAppBar: true,
      body: Container(
        width: double.infinity,
        height: double.infinity,
        color: Colors.blue,
      ),
      bottomNavigationBar: bottomNavBar,
      floatingActionButton: addPostButton,
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }

  Widget get bottomNavBar {
    return BottomAppBar(
      color: Colors.red,
      shape: CircularNotchedRectangle(),
      elevation: 0,
      notchMargin: 10,
      child: BottomNavigationBar(
        elevation: 0,
        items: [
          BottomNavigationBarItem(
            icon: Icon(MdiIcons.homeOutline),
            activeIcon: Icon(MdiIcons.home),
            title: Text("Home"),
          ),
          BottomNavigationBarItem(
            icon: Icon(MdiIcons.accountOutline),
            activeIcon: Icon(MdiIcons.account),
            title: Text("Profile"),
          ),
        ],
      ),
    );
  }

  Widget get addPostButton {
    return FloatingActionButton(
      focusElevation: 0,
      onPressed: () {},
      child: Icon(
        MdiIcons.mapMarkerPlusOutline,
        size: 30,
      ),
    );
  }
}

带有红色页脚的屏幕截图

Change your code as per below then check:

 Widget get bottomNavBar {
  return BottomNavigationBar(
    elevation: 0,
    items: [
      BottomNavigationBarItem(
        icon: Icon(MdiIcons.homeOutline),
        activeIcon: Icon(MdiIcons.home),
        title: Text("Home"),
      ),
      BottomNavigationBarItem(
        icon: Icon(MdiIcons.accountOutline),
        activeIcon: Icon(MdiIcons.account),
        title: Text("Profile"),
      ),
    ],
   );
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM