如何对齐在颤音中抵消

发布于 2025-01-21 23:07:18 字数 4115 浏览 0 评论 0原文

我在浮动按钮上有此菜单,但是我无法正确对齐。

我希望它直接显示在浮动按钮上方,并以此为中心,这是我当前的偏移量,也是它的照片。 图片

我希望弹出菜单在图片2

”中

        floatingActionButton: FloatingActionButton(
            onPressed: () {},
            child: myPopMenu(context),
            backgroundColor: Colors.white,
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        bottomNavigationBar: BottomNav(
            onChange: (a) {
                Navigator.of(context).pushAndRemoveUntil(
                    MaterialPageRoute(
                        builder: (c) => AppPage(initialPage: a,)),
                    (route) => false);
            },
        ),
    );
}


Widget myPopMenu(BuildContext context) {

    return Theme(
        data: Theme.of(context).copyWith(
            cardColor: Colors.white60,
        ),
        child: PopupMenuButton(
            offset: const Offset(-90, 100),
            icon: Image.asset('assets/logo.png', fit: BoxFit.cover, height: 40),
            onCanceled: () {
                setState(() {
                    isClicked = false;
                });
            },
            onSelected: (value) {
                setState(() {
                    isClicked = false;
                });

                print('pop up clicked');
                if (value == 0) {
                    alertRate();
                } else if (value == 1){
                    alertServices();
                }else if (value == 2) {
                    alertAdditonalInfo();
                }else if (value == 3){
                    alertReport();
                }
            },
            itemBuilder: (context) {
                setState(() {
                    isClicked = true;
                });

                return [
                    PopupMenuItem(
                        child: Center(
                            child: Text(
                                'Rate & Review',
                                style: TextStyle(color: Colors.black),
                            ),
                        ),
                        value: 0,
                    ),
                    PopupMenuItem(
                        height: 4,
                        child: Container(
                            height: 2,
                            color: Colors.black,
                        ),
                    ),
                    PopupMenuItem(
                        child: Center(
                            child: Text(
                                'Edit Available Services',
                                style: TextStyle(color: Colors.black),
                            ),
                        ),
                        value: 1,
                    ),
                    PopupMenuItem(
                        height: 4,
                        child: Container(
                            height: 2,
                            color: Colors.black,
                        ),
                    ),
                    PopupMenuItem(
                        child: Center(
                            child: Text(
                                'Edit Social Accounts',
                                style: TextStyle(color: Colors.black),
                            ),
                        ),
                        value: 2,
                    ),
                    PopupMenuItem(
                        height: 4,
                        child: Container(
                            height: 2,
                            color: Colors.black,
                        ),
                    ),
                    PopupMenuItem(
                        child: Center(
                            child: Text(
                                'Report an Issue',
                                style: TextStyle(color: Colors.black),
                            ),
                        ),
                        value: 3,
                    ),
                ];
            }),
    );
}

I have this menu on the floating button, but I could not align it correctly.

I want it to show directly above the floating button and centered this is my current offset and also the photo of it. Picture.

I want the pop up menu to be like this on picture 2

Enter image description here

This is the source code of the pop up menu

        floatingActionButton: FloatingActionButton(
            onPressed: () {},
            child: myPopMenu(context),
            backgroundColor: Colors.white,
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        bottomNavigationBar: BottomNav(
            onChange: (a) {
                Navigator.of(context).pushAndRemoveUntil(
                    MaterialPageRoute(
                        builder: (c) => AppPage(initialPage: a,)),
                    (route) => false);
            },
        ),
    );
}


Widget myPopMenu(BuildContext context) {

    return Theme(
        data: Theme.of(context).copyWith(
            cardColor: Colors.white60,
        ),
        child: PopupMenuButton(
            offset: const Offset(-90, 100),
            icon: Image.asset('assets/logo.png', fit: BoxFit.cover, height: 40),
            onCanceled: () {
                setState(() {
                    isClicked = false;
                });
            },
            onSelected: (value) {
                setState(() {
                    isClicked = false;
                });

                print('pop up clicked');
                if (value == 0) {
                    alertRate();
                } else if (value == 1){
                    alertServices();
                }else if (value == 2) {
                    alertAdditonalInfo();
                }else if (value == 3){
                    alertReport();
                }
            },
            itemBuilder: (context) {
                setState(() {
                    isClicked = true;
                });

                return [
                    PopupMenuItem(
                        child: Center(
                            child: Text(
                                'Rate & Review',
                                style: TextStyle(color: Colors.black),
                            ),
                        ),
                        value: 0,
                    ),
                    PopupMenuItem(
                        height: 4,
                        child: Container(
                            height: 2,
                            color: Colors.black,
                        ),
                    ),
                    PopupMenuItem(
                        child: Center(
                            child: Text(
                                'Edit Available Services',
                                style: TextStyle(color: Colors.black),
                            ),
                        ),
                        value: 1,
                    ),
                    PopupMenuItem(
                        height: 4,
                        child: Container(
                            height: 2,
                            color: Colors.black,
                        ),
                    ),
                    PopupMenuItem(
                        child: Center(
                            child: Text(
                                'Edit Social Accounts',
                                style: TextStyle(color: Colors.black),
                            ),
                        ),
                        value: 2,
                    ),
                    PopupMenuItem(
                        height: 4,
                        child: Container(
                            height: 2,
                            color: Colors.black,
                        ),
                    ),
                    PopupMenuItem(
                        child: Center(
                            child: Text(
                                'Report an Issue',
                                style: TextStyle(color: Colors.black),
                            ),
                        ),
                        value: 3,
                    ),
                ];
            }),
    );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思碎 2025-01-28 23:07:18

我认为最好的选择是使用对话框。

这是演示代码:

只需在您的函数中调用此信息:

Future<void> _displayDialog() async {
await showDialog(
  context: context,
  builder: (BuildContext context) {
    return SimpleDialog(
      backgroundColor: Colors.white60,
      elevation: 5.0,
      children: [
        SimpleDialogOption(
          onPressed: () {
            //  Do Something
            Navigator.pop(context);
          },
          child: const Text(
            'Rate & Review',
            textAlign: TextAlign.center,
            style: TextStyle(color: Colors.black),
          ),
        ),
        const Divider(
            color: Colors.black,
            thickness: 2.0,
            endIndent: 16.0,
            indent: 16.0),
        SimpleDialogOption(
          onPressed: () {
            //  Do Something
            Navigator.pop(context);
          },
          child: const Text(
            'Edit Available Services',
            textAlign: TextAlign.center,
            style: TextStyle(color: Colors.black),
          ),
        ),
        const Divider(
            color: Colors.black,
            thickness: 2.0,
            endIndent: 16.0,
            indent: 16.0),
        SimpleDialogOption(
          onPressed: () {
            //  Do Something
            Navigator.pop(context);
          },
          child: const Text(
            'Edit Social Accounts',
             textAlign: TextAlign.center,
            style: TextStyle(color: Colors.black),
          ),
        ),
        const Divider(
            color: Colors.black,
            thickness: 2.0,
            endIndent: 16.0,
            indent: 16.0),
        SimpleDialogOption(
          onPressed: () {
            //  Do Something
            Navigator.pop(context);
          },
          child: const Text(
            'Report an Issue',
            textAlign: TextAlign.center,
            style: TextStyle(color: Colors.black),
          ),
        ),
      ],
    );
  },
);}

”在此处输入图像说明”

I think the best option is to use a dialog.

Here is demo code:

Just call this in your function:

Future<void> _displayDialog() async {
await showDialog(
  context: context,
  builder: (BuildContext context) {
    return SimpleDialog(
      backgroundColor: Colors.white60,
      elevation: 5.0,
      children: [
        SimpleDialogOption(
          onPressed: () {
            //  Do Something
            Navigator.pop(context);
          },
          child: const Text(
            'Rate & Review',
            textAlign: TextAlign.center,
            style: TextStyle(color: Colors.black),
          ),
        ),
        const Divider(
            color: Colors.black,
            thickness: 2.0,
            endIndent: 16.0,
            indent: 16.0),
        SimpleDialogOption(
          onPressed: () {
            //  Do Something
            Navigator.pop(context);
          },
          child: const Text(
            'Edit Available Services',
            textAlign: TextAlign.center,
            style: TextStyle(color: Colors.black),
          ),
        ),
        const Divider(
            color: Colors.black,
            thickness: 2.0,
            endIndent: 16.0,
            indent: 16.0),
        SimpleDialogOption(
          onPressed: () {
            //  Do Something
            Navigator.pop(context);
          },
          child: const Text(
            'Edit Social Accounts',
             textAlign: TextAlign.center,
            style: TextStyle(color: Colors.black),
          ),
        ),
        const Divider(
            color: Colors.black,
            thickness: 2.0,
            endIndent: 16.0,
            indent: 16.0),
        SimpleDialogOption(
          onPressed: () {
            //  Do Something
            Navigator.pop(context);
          },
          child: const Text(
            'Report an Issue',
            textAlign: TextAlign.center,
            style: TextStyle(color: Colors.black),
          ),
        ),
      ],
    );
  },
);}

Enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文