Flutter-将弹出菜单按钮添加到BottomNavigationBar中的中间图标

时间:2020-05-05 15:59:01

标签: flutter dart flutter-layout

我想向BottomNavigationBar的中间图标添加一个弹出窗口。我尝试按照显示的代码进行操作。只需单击“添加”图标,如何添加popupmenubutton?

位置代码块

 RelativeRect buttonMenuPosition(BuildContext c) {
    final RenderBox bar = c.findRenderObject();
    final RenderBox overlay = Overlay.of(c).context.findRenderObject();
    final RelativeRect position = RelativeRect.fromRect(
      Rect.fromPoints(
        bar.localToGlobal(bar.size.bottomRight(Offset.zero), ancestor: overlay),
        bar.localToGlobal(bar.size.bottomCenter(Offset.zero), ancestor: overlay),
      ),
      Offset.zero & overlay.size,
    );
    return position;
  }` 

身体

 body: _widgetOptions.elementAt(_selectedBottomNavBarIndex),
      bottomNavigationBar: BottomNavigationBar(
          showSelectedLabels: false,
          showUnselectedLabels: false,
          iconSize: 24,
          selectedFontSize: 0,
          unselectedFontSize: 0,
          type: BottomNavigationBarType.fixed,
          key: key,
          items: [
            BottomNavigationBarItem(
             ...
            ),`

onTap部分

  if (index == 2) {
              final result = await showMenu(
                context: context,
                position: position,
                items: <PopupMenuItem<String>>[
                  new PopupMenuItem<String>(
                    child: GestureDetector(
                      onTap: () {
                        Navigator.push(
                          context,
                          MaterialPageRoute(
                              builder: (context) => RecordScreenOrj()),
                        );
                      },

photo

0 个答案:

没有答案