将自定义的高度和宽度设置为警报

时间:2019-09-27 12:51:56

标签: flutter dart

我已经在项目中应用了sweetalert,我的应用是横向应用,sweetalert处于全屏状态,我想将自定义宽度和高度设置为sweetalert

SweetAlert.show(context,
                      title: "Just show a message",
                      subtitle: "Sweet alert is pretty",
                      style: SweetAlertStyle.confirm,
                      showCancelButton: true, onPress: (bool isConfirm) {
        if (isConfirm) {
          SweetAlert.show(context,style: SweetAlertStyle.success,title: "Success");
          // return false to keep dialog
          return false;
        }
      });

2 个答案:

答案 0 :(得分:1)

好的,用三引号('''String''')包裹您的字符串,根据期望的高度添加所需的空格或换行。

https://api.dartlang.org/stable/2.5.0/dart-core/String-class.html

                        SweetAlert.show(
                            context,
                            title: '''

            Just show a message

                            ''',
                            subtitle: '''


            Sweet alert is pretty


                                ''',
                            style: SweetAlertStyle.confirm,
                            showCancelButton: true,
                            onPress: (bool isConfirm) {
                            if (isConfirm) {
                                SweetAlert.show(context,
                                    style: SweetAlertStyle.success, title: "Success");
                                // return false to keep dialog
                                return false;
                            }
                            },
                        );

enter image description here

答案 1 :(得分:1)

根据我对您问题的评估,没有任何选择。但是我认为rflutter_alert是最好的选择,而不是sweetalert,在这里您可以使用宽度和高度来自定义它。希望对您有所帮助。您可以在按钮中添加多个按钮:[],

import 'package:rflutter_alert/rflutter_alert.dart';
    Alert(
          context: context,
          type: AlertType.error,
          title: "RFLUTTER ALERT",
          desc: "Flutter is more awesome with RFlutter Alert.",
          buttons: [
            DialogButton(
              child: Text(
                "COOL",
                style: TextStyle(color: Colors.white, fontSize: 20),
              ),
              onPressed: () => Navigator.pop(context),
              width: 120,
            )
          ],
        ).show();