Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 警报对话框中垂直对齐的扁平按钮?_Flutter_Dart - Fatal编程技术网

Flutter 警报对话框中垂直对齐的扁平按钮?

Flutter 警报对话框中垂直对齐的扁平按钮?,flutter,dart,Flutter,Dart,我想在颤振中显示一个带有3个按钮的AlertDialog,但是垂直对齐,因为按钮的文本占用了太多空间。到目前为止,我只能水平显示它们。你知道怎么解决吗?这篇文章()中的解决方案对我不起作用,仍然水平显示 static Future<void> showLogoutAllDevicesOrOnlyThisDialog( BuildContext context) { var b1 = FlatButton( textColor: Colors.red

我想在颤振中显示一个带有3个按钮的AlertDialog,但是垂直对齐,因为按钮的文本占用了太多空间。到目前为止,我只能水平显示它们。你知道怎么解决吗?这篇文章()中的解决方案对我不起作用,仍然水平显示

  static Future<void> showLogoutAllDevicesOrOnlyThisDialog(
      BuildContext context) {
    var b1 = FlatButton(
      textColor: Colors.red,
      child: Text('Only on this device'),
      onPressed: () {
        Navigator.of(context).pop();
        RxBus.post(HideSpinnerEvent());
      },
    );
    var b2 = FlatButton(
      textColor: Colors.red,
      child: Text('On all devices'),
      onPressed: () {
        Navigator.of(context).pop();
        RxBus.post(HideSpinnerEvent());
      },
    );

    var b3 = FlatButton(
      child: Text('Cancel'),
      onPressed: () {
        Navigator.of(context).pop();
      },
    );

    return showDialog<void>(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text(''),
          content: Text(
              "Möchtest du dich auf allen Geräten abmelden oder nur auf diesem Gerät?"),
          actions: <Widget>[
            b1, b2, b3
          ],

        );
      },
    );
  }
}
静态未来显示LogoutAllDevicesOronlyThisDialog(
BuildContext(上下文){
变量b1=扁平按钮(
textColor:Colors.red,
子项:文本(“仅在此设备上”),
已按下:(){
Navigator.of(context.pop();
RxBus.post(HideSpinnerEvent());
},
);
var b2=扁平按钮(
textColor:Colors.red,
子项:文本(“在所有设备上”),
已按下:(){
Navigator.of(context.pop();
RxBus.post(HideSpinnerEvent());
},
);
var b3=扁平按钮(
子项:文本('Cancel'),
已按下:(){
Navigator.of(context.pop();
},
);
返回显示对话框(
上下文:上下文,
生成器:(BuildContext上下文){
返回警报对话框(
标题:文本(“”),
内容:文本(
“这是艾伦·格尔滕的作品吗?”),
行动:[
b1、b2、b3
],
);
},
);
}
}

返回警报对话框(
标题:文本(“”),
内容:文本(“阿伦·格尔滕·阿梅尔登·奥德·努尔·奥夫·迪塞姆·格尔特吗?”),
行动:[
纵队(
crossAxisAlignment:crossAxisAlignment.end,
儿童:[
b1、b2、b3
]
)
],
))

返回警报对话框(
标题:文本(“”),
内容:文本(“阿伦·格尔滕·阿梅尔登·奥德·努尔·奥夫·迪塞姆·格尔特吗?”),
行动:[
纵队(
crossAxisAlignment:crossAxisAlignment.end,
儿童:[
b1、b2、b3
]
)
],

))

您可以创建自己的自定义对话框,并根据需要进行任何操作,如下所示:

void _showDialog() {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (context) {
        return Dialog(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(2),
          ),
          elevation: 0,
          child: Padding(
            padding: EdgeInsets.symmetric(
              horizontal: 20,
              vertical: 10,
            ),
            child: IntrinsicWidth(
              child: IntrinsicHeight(
                child: Column(
                  children: <Widget>[
                    SizedBox(
                      height: 10,
                    ),
                    Text(
                      "Custom Alert Dialog",
                      style: TextStyle(
                        fontWeight: FontWeight.w700,
                        fontFamily: "Roboto",
                        fontSize: 18,
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Text(
                      "This is a message inside your custom Alert Dialog!\nFeel free to change it to fit your needs.",
                      style: TextStyle(
                        fontFamily: "Roboto",
                        fontWeight: FontWeight.w400,
                        fontSize: 16,
                      ),
                    ),
                    SizedBox(
                      height: 30,
                    ),
                    Column(
                      children: <Widget>[
                        Align(
                          alignment: Alignment.bottomRight,
                          child: FlatButton(
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                            child: Text("OK"),
                          ),
                        ),
                        Align(
                          alignment: Alignment.bottomRight,
                          child: FlatButton(
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                            child: Text("Not Sure"),
                          ),
                        ),
                        Align(
                          alignment: Alignment.bottomRight,
                          child: FlatButton(
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                            child: Text("Cancel"),
                          ),
                        ),
                      ],
                    )
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
void _showDialog() {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (context) {
        return Dialog(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(2),
          ),
          elevation: 0,
          child: Padding(
            padding: EdgeInsets.symmetric(
              horizontal: 20,
              vertical: 10,
            ),
            child: IntrinsicWidth(
              child: IntrinsicHeight(
                child: Column(
                  children: <Widget>[
                    SizedBox(
                      height: 10,
                    ),
                    Text(
                      "Custom Alert Dialog",
                      style: TextStyle(
                        fontWeight: FontWeight.w700,
                        fontFamily: "Roboto",
                        fontSize: 18,
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Text(
                      "This is a message inside your custom Alert Dialog!\nFeel free to change it to fit your needs.",
                      style: TextStyle(
                        fontFamily: "Roboto",
                        fontWeight: FontWeight.w400,
                        fontSize: 16,
                      ),
                    ),
                    SizedBox(
                      height: 30,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        FlatButton(
                          onPressed: () {
                            Navigator.of(context).pop();
                          },
                          child: Text("OK"),
                        ),
                        FlatButton(
                          onPressed: () {
                            Navigator.of(context).pop();
                          },
                          child: Text("Not Sure"),
                        ),
                        FlatButton(
                          onPressed: () {
                            Navigator.of(context).pop();
                          },
                          child: Text("Cancel"),
                        ),
                      ],
                    )
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
void\u showDialog(){
显示对话框(
上下文:上下文,
禁止:错误,
生成器:(上下文){
返回对话框(
形状:圆形矩形边框(
边界半径:边界半径。圆形(2),
),
海拔:0,
孩子:填充(
填充:EdgeInsets.symmetric(
横向:20,
垂直:10,
),
子:内部宽度(
孩子:内在的(
子:列(
儿童:[
大小盒子(
身高:10,
),
正文(
“自定义警报对话框”,
样式:TextStyle(
fontWeight:fontWeight.w700,
fontFamily:“机器人”,
尺码:18,
),
),
大小盒子(
身高:20,
),
正文(
“这是自定义警报对话框中的一条消息!\n您可以自由更改它以满足您的需要。”,
样式:TextStyle(
fontFamily:“机器人”,
fontWeight:fontWeight.w400,
尺寸:16,
),
),
大小盒子(
身高:30,
),
纵队(
儿童:[
对齐(
对齐:对齐。右下角,
孩子:扁平按钮(
已按下:(){
Navigator.of(context.pop();
},
孩子:文本(“OK”),
),
),
对齐(
对齐:对齐。右下角,
孩子:扁平按钮(
已按下:(){
Navigator.of(context.pop();
},
子项:文本(“不确定”),
),
),
对齐(
对齐:对齐。右下角,
孩子:扁平按钮(
已按下:(){
Navigator.of(context.pop();
},
子项:文本(“取消”),
),
),
],
)
],
),
),
),
),
);
},
);
你的最终结果是:

但如果您正在寻找行设计,则需要以下内容:

void _showDialog() {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (context) {
        return Dialog(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(2),
          ),
          elevation: 0,
          child: Padding(
            padding: EdgeInsets.symmetric(
              horizontal: 20,
              vertical: 10,
            ),
            child: IntrinsicWidth(
              child: IntrinsicHeight(
                child: Column(
                  children: <Widget>[
                    SizedBox(
                      height: 10,
                    ),
                    Text(
                      "Custom Alert Dialog",
                      style: TextStyle(
                        fontWeight: FontWeight.w700,
                        fontFamily: "Roboto",
                        fontSize: 18,
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Text(
                      "This is a message inside your custom Alert Dialog!\nFeel free to change it to fit your needs.",
                      style: TextStyle(
                        fontFamily: "Roboto",
                        fontWeight: FontWeight.w400,
                        fontSize: 16,
                      ),
                    ),
                    SizedBox(
                      height: 30,
                    ),
                    Column(
                      children: <Widget>[
                        Align(
                          alignment: Alignment.bottomRight,
                          child: FlatButton(
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                            child: Text("OK"),
                          ),
                        ),
                        Align(
                          alignment: Alignment.bottomRight,
                          child: FlatButton(
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                            child: Text("Not Sure"),
                          ),
                        ),
                        Align(
                          alignment: Alignment.bottomRight,
                          child: FlatButton(
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                            child: Text("Cancel"),
                          ),
                        ),
                      ],
                    )
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
void _showDialog() {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (context) {
        return Dialog(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(2),
          ),
          elevation: 0,
          child: Padding(
            padding: EdgeInsets.symmetric(
              horizontal: 20,
              vertical: 10,
            ),
            child: IntrinsicWidth(
              child: IntrinsicHeight(
                child: Column(
                  children: <Widget>[
                    SizedBox(
                      height: 10,
                    ),
                    Text(
                      "Custom Alert Dialog",
                      style: TextStyle(
                        fontWeight: FontWeight.w700,
                        fontFamily: "Roboto",
                        fontSize: 18,
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Text(
                      "This is a message inside your custom Alert Dialog!\nFeel free to change it to fit your needs.",
                      style: TextStyle(
                        fontFamily: "Roboto",
                        fontWeight: FontWeight.w400,
                        fontSize: 16,
                      ),
                    ),
                    SizedBox(
                      height: 30,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        FlatButton(
                          onPressed: () {
                            Navigator.of(context).pop();
                          },
                          child: Text("OK"),
                        ),
                        FlatButton(
                          onPressed: () {
                            Navigator.of(context).pop();
                          },
                          child: Text("Not Sure"),
                        ),
                        FlatButton(
                          onPressed: () {
                            Navigator.of(context).pop();
                          },
                          child: Text("Cancel"),
                        ),
                      ],
                    )
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
void\u showDialog(){
显示对话框(
上下文:上下文,
禁止:错误,
生成器:(上下文){
返回对话框(
形状:圆形矩形边框(
边界半径:边界半径。圆形(2),
),
海拔:0,
孩子:填充(
填充:EdgeInsets.symmetric(
横向:20,
垂直:10,
),
子:内部宽度(
孩子:内在的(
子:列(
儿童:[
大小盒子(
身高:10,
),
正文(
“自定义警报对话框”,
样式:TextStyle(
fontWeight:fontWeight.w700,
fontFamily:“机器人”,
尺码:18,
),
),