Flutter -在BottomNavigationBar的中间图标上添加一个弹出式菜单按钮。

问题描述 投票:0回答:1

我想在BottomNavigationBar的中间图标上添加一个弹出窗口。我试图按照我展示的代码来做。当我只是点击添加图标时,如何添加弹出式菜单按钮?

代码块的位置

 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(
             ...
            ),`

开机部分

  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()),
                        );
                      },

照片

flutter dart flutter-layout
1个回答
0
投票
Try this function, 


child: Padding(
            padding: EdgeInsets.only(left: parentWidth * .03),
            child: Column(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.only(top: parentHeight * .01),
                  child: new Container(
                    height: parentHeight * .045,
                    width: parentHeight * .045,
                    child: FloatingActionButton(
                      backgroundColor: Colors.pinkAccent,
                      onPressed: () {
                        showGeneralDialog(
                            barrierColor: Colors.black.withOpacity(0.5),
                            transitionBuilder: (context, a1, a2, widget) {
                              final curvedValue =
                                  Curves.easeInOutBack.transform(a1.value) -
                                      1.0;
                              return Transform(
                                transform: Matrix4.translationValues(
                                    0.0, curvedValue * 200, 0.0),
                                child: Opacity(
                                  opacity: a1.value,
                                  child: new DialogForAsk(_controller, this),
                                ),
                              );
                            },
                            transitionDuration: Duration(milliseconds: 200),
                            barrierDismissible: true,
                            barrierLabel: '',
                            context: context,
                            pageBuilder: (context, animation2, animation1) {});
                      },
                      child: Icon(
                        Icons.add,
                        size: parentHeight * .04,
                        color: Colors.white,
                      ),
                    ),
                  ),
                ),
© www.soinside.com 2019 - 2024. All rights reserved.