Flutter - добавление кнопки всплывающего меню к среднему значку в BottomNavigationBar - PullRequest
0 голосов
/ 05 мая 2020

Я хочу добавить всплывающее окно к среднему значку 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

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

фото

1 Ответ

0 голосов
/ 06 мая 2020
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,
                      ),
                    ),
                  ),
                ),
...