如何从 Flutter 的 bottomnavigationbar 制作弹出菜单?

How to make popup menu from bottomnavigationbar in Flutter?

我正在尝试实现类似此屏幕截图的功能,即底部导航栏在页面之间切换,但中间按钮启动底部 sheet 或弹出菜单等其他操作并停留在该页面上...

class _HomePageState extends State<HomePage> {
  PersistentTabController _controller;

  @override
  void initState() {
    super.initState();

    _controller = PersistentTabController(initialIndex: 0);
    _hideNavBar = false;
  }

  List<Widget> _buildScreens() {
    return [
      MyHomePage(),

      AddPage(), // this need to be action button not new page...

      MyActivity(),
    ];
  }
  List<PersistentBottomNavBarItem> _navBarsItems() {
    return [
      PersistentBottomNavBarItem(
        icon: Icon(Icons.home),
        title: "Home",
        activeColor: Colors.purpleAccent,
        inactiveColor: Colors.grey,
      ),
      PersistentBottomNavBarItem(
        icon: Icon(Icons.add),
        title: ("Add"),
        activeColor: Colors.purpleAccent,
        inactiveColor: Colors.grey,
      ),
      PersistentBottomNavBarItem(
        icon: Icon(Icons.search),
        title: ("MyAct"),
        activeColor: Colors.purpleAccent,
        inactiveColor: Colors.grey,
      ),
    ];
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PersistentTabView.custom(
        context,
        controller: _controller,
        screens: _buildScreens(),
        confineInSafeArea: true,
        itemCount: 3,
        handleAndroidBackButtonPress: true,
        resizeToAvoidBottomInset: false,
        stateManagement: true,
        hideNavigationBar: _hideNavBar,
        screenTransitionAnimation: ScreenTransitionAnimation(
          animateTabTransition: true,
          curve: Curves.ease,
          duration: Duration(milliseconds: 200),
        ),
        customWidget: CustomNavBarWidget(
          items: _navBarsItems(),
          onItemSelected: (index) {

            setState(() {
              _controller.index = index; // THIS IS CRITICAL!! Don't miss it!
            });
          },
          selectedIndex: _controller.index,
        ),
      ),
);
}

IM 使用 persistenNavBar,但我认为常规底部导航情况是相同的... 我想我可以制作自定义底部导航栏,或具有不同小部件类型的列表?

您可以使用

showModalBottomSheet()

来自 Flutter 并设置参数如下:

showModalBottomSheet(
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), //for the round edges
    builder: (context) {
        return Container(
            //specify height, so that it does not fill the entire screen
            child: Column(children: []) //what you want to have inside, I suggest using a column
        );
    }
    context: context,
    isDismissible: //boolean if you want to be able to dismiss it
    isScrollControlled: //boolean if something does not display, try that
);

然后你就可以在BottomNavigationBar tap上执行这个函数了。