简体   繁体   English

如何在 flutter 的屏幕顶部中心显示自定义对话框?

[英]How to show custom dialog at the top center of the screen in flutter?

I am going to show a custom dialog at the top center of the screen.我将在屏幕顶部中心显示一个自定义对话框。

I've attached a screenshot .我附上了截图

How can I accomplish this?我怎样才能做到这一点? Default position of Dialog is center of the screen. Dialog 的默认 position 是屏幕的中心。

showDialog(
    context: context,
    builder: (BuildContext context) {
      return alert;
    },
);

You can use Align and Material widget.您可以使用对齐和材质小部件。 ( Alignment.topCenter ) ie Alignment.topCenter )即

void showCustomDialog(BuildContext context, String message) {
    showDialog(
      barrierDismissible: false,
      context: context,
      builder: (BuildContext cxt) {
        return Align(
          alignment: Alignment.topCenter,
          child: Padding(
            padding: EdgeInsets.all(16),
            child: Material(
              color: Colors.green,
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(15)),
              child: Padding(
                padding: EdgeInsets.all(16),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Row(
                      children: [
                        InkWell(
                            onTap: () {
                              Navigator.of(context).pop();
                            },
                            child: Image.asset("assets/close.png")),
                        SizedBox(width: 16),
                        Expanded(
                          child: Text(
                            message,
                            style: TextStyle(
                              color: Colors.white,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当通知到达时,如何在任何屏幕中显示自定义对话框? - How to show a custom dialog in any screen in when notification arrived flutter? Flutter/Dart 如何将 sizedbox 居中到屏幕的顶部中心? - Flutter/Dart How to center sizedbox to top center of screen? flutter 定位对话框到屏幕中心 - flutter positioning dialog to screen center 如何在颤振中显示自定义吐司对话框? - How to show custom toast dialog in flutter? 如何在活动之上创建透明的全屏对话框 - Flutter - How to create a transparent full screen dialog on top of activity - Flutter Flutter 显示全屏对话框 - Flutter show full screen dialog 如何在 Flutter 中离开屏幕之前显示确认对话框 - How to show confirm dialog before leave screen in Flutter 在 Flutter 的登录屏幕中显示循环进度对话框,如何在 Flutter 中实现进度对话框? - Show Circular Progress Dialog in Login Screen in Flutter, how to implement progress dialog in flutter? 如何在 Flutter 中将一个小部件与屏幕顶部对齐并将另一个小部件居中放置在屏幕中间? - How do I align one widget to the top of the screen and center another widget to the middle of the screen in Flutter? 仅在部分屏幕上显示 Flutter 对话框 - Show Flutter dialog only on part of the screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM