【问题标题】:How to make fullscreen alertDialog in flutter如何在颤动中制作全屏警报对话框
【发布时间】:2020-04-14 18:35:40
【问题描述】:

我需要帮助才能使我的警报对话框全屏显示,这是我目前拥有的代码,我该如何实现?我不知道是否可以将宽度定义为屏幕尺寸和高度。

    createNewMessage() {
    return showDialog(
        barrierDismissible: false,
        context: context,
        builder: (BuildContext context) {
          return StatefulBuilder(builder: (context, setState) {
            return WillPopScope(
                onWillPop: () {},
                child: Container(
                    child: new AlertDialog(
                  title: Column(
                    children: <Widget>[
                      new Text(Translations.of(context).trans('finishmessage') +
                          '?'),
                      Container(
                        height: 20,
                      ),
                      DropdownButton(
                        hint: new Text('Para'),
                        isExpanded: true,
                        onChanged: (value) {
                          setState(() => selected = value);
                        },
                        value: selected,
                        items: workers.map((worker) {
                          return DropdownMenuItem(
                            child: new Text(worker.vNome),
                            value: worker.vCodigo,
                          );
                        }).toList(),
                      ),
                      Container(
                        height: 10,
                      ),
                      TextField(decoration: InputDecoration(labelText: "Data")),
                      Container(
                        height: 10,
                      ),
                      TextField(decoration: InputDecoration(labelText: "Hora")),
                      Container(
                        height: 10,
                      ),
                      TextField(
                          decoration: InputDecoration(labelText: 'Mensagem'))
                    ],
                  ),
                  actions: <Widget>[
                    FlatButton(
                        child:
                            Text(Translations.of(context).trans('sendMessage')),
                        onPressed: () {}),
                    FlatButton(
                        child:
                            Text(Translations.of(context).trans('closealert')),
                        onPressed: () {
                          setState(() => selected = null);
                          Navigator.of(context).pop();
                        }),
                  ],
                )));
          });
        });
  }

这是目前的结果:
警报对话框当前

感谢您的帮助和时间

【问题讨论】:

    标签: flutter flutter-alertdialog


    【解决方案1】:

    如何不使用 AlertDialog,而是使用您自己的小部件并根据需要进行自定义。试试下面的代码

    createNewMessage() {
      return showDialog(
        barrierDismissible: false,
        context: context,
        builder: (BuildContext context) {
          return StatefulBuilder(
            builder: (context, setState) {
              return WillPopScope(
                  onWillPop: () {
                    return Future.value(true);
                  },
                  child: Material(
                    child: Container(
                      padding: const EdgeInsets.all(16.0),
                      width: double.infinity,
                      height: double.infinity,
                      child: Column(
                        children: <Widget>[
                          new Text(Translations.of(context).trans('finishmessage') +
                              '?'),
                          Container(
                            height: 20,
                          ),
                          DropdownButton(
                            hint: new Text('Para'),
                            isExpanded: true,
                            onChanged: (value) {
                              setState(() => selected = value);
                            },
                            value: selected,
                            items: workers.map((worker) {
                              return DropdownMenuItem(
                                child: new Text(worker.vNome),
                                value: worker.vCodigo,
                              );
                            }).toList(),
                          ),
                          Container(
                            height: 10,
                          ),
                          TextField(decoration: InputDecoration(labelText: "Data")),
                          Container(
                            height: 10,
                          ),
                          TextField(decoration: InputDecoration(labelText: "Hora")),
                          Container(
                            height: 10,
                          ),
                          TextField(
                              decoration: InputDecoration(labelText: 'Mensagem')),
                          Spacer(),
                          Row(
                            children: <Widget>[
                              Spacer(),
                              FlatButton(
                                  child: Text(Translations.of(context)
                                      .trans('sendMessage')),
                                  onPressed: () {}),
                              FlatButton(
                                  child: Text(
                                      Translations.of(context).trans('closealert')),
                                  onPressed: () {
                                    setState(() => selected = null);
                                    Navigator.of(context).pop();
                                  }),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ));
            },
          );
        },
      );
    }
    

    【讨论】:

      【解决方案2】:

      试试这个,它对我有用

      showGeneralDialog(
        context: context,
        barrierDismissible: true,
        barrierLabel: MaterialLocalizations.of(context)
            .modalBarrierDismissLabel,
        barrierColor: Colors.black45,
        transitionDuration: const Duration(milliseconds: 200),
        pageBuilder: (BuildContext buildContext,
            Animation animation,
            Animation secondaryAnimation) {
          return Center(
            child: Container(
              width: MediaQuery.of(context).size.width - 10,
              height: MediaQuery.of(context).size.height -  80,
              padding: EdgeInsets.all(20),
              color: Colors.white,
              child: Column(
                children: [
                  RaisedButton(
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                    child: Text(
                      "Save",
                      style: TextStyle(color: Colors.white),
                    ),
                    color: const Color(0xFF1BC0C5),
                  )
                ],
              ),
            ),
          );
        });
      

      【讨论】:

        猜你喜欢
        • 2016-11-27
        • 2019-01-25
        • 2020-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-12
        • 1970-01-01
        相关资源
        最近更新 更多