代码之家  ›  专栏  ›  技术社区  ›  MeLean

如何设计颤振中的警报对话动作

  •  8
  • MeLean  · 技术社区  · 6 年前

    我使用此方法显示警报对话框:

    提交(message){
    如果(message.isnotempty){
    显示对话框(
    上下文:上下文,
    barrierdismissible:错误,
    生成器:(BuildContext上下文){
    返回警报对话框(
    标题:中心(子级:文本(“警报”)),
    内容:行(
    mainaxisalignment:mainaxisalignment.center,
    十字轴定位:十字轴定位.center,
    子项:<widget>。[
    展开(
    子级:文本(
    消息,
    textAlign:textAlign.center,
    样式:textstyle(
    颜色:颜色。红色,
    
    )
    )
    )
    ,
    )
    操作:<widget>。[
    扁平按钮(
    子:文本(“取消”),
    按下时:(){
    navigator.of(context.pop();
    }
    扁平按钮(
    子:文本(“确定”),
    按下时:(){
    _ inputExtController.clear();
    navigator.of(context.pop();
    })
    ,
    ;
    }
    ;
    }
    
    
    

    enter image description here

    4 回复  |  直到 6 年前
        1
  •  9
  •   Bostrot    6 年前

    AlertDialog ButtonBar widget alignment: MainAxisAlignment.spaceBetween this answer

    actions Row RaisedButtons

    Row (
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
            RaisedButton(), // button 1
            RaisedButton(), // button 2
        ]
    )
    

    Column content

        2
  •  3
  •   Bostrot    6 年前

    _onSubmit(message) {
        if (message.isNotEmpty) {
          showDialog(
            context: context,
            barrierDismissible: false,
            builder: (BuildContext context) {
              return AlertDialog(
                title: Center(child: Text('Alert')),
                content: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children : <Widget>[
                    Expanded(
                      child: Text(
                        message,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: Colors.red,
    
                        ),
                      ),
                    ),
    
             FlatButton(
                      child: Text('Cancel'),
                      onPressed: () {
                        Navigator.of(context).pop();
                      }),
                  FlatButton(
                      child: Text('Ok'),
                      onPressed: () {
                        _inputTextController.clear();
                        Navigator.of(context).pop();
                      })
                  ],
                ),
              );
            },
          );
        }
      }
    
        3
  •  3
  •   Jack Sun    6 年前

    showDialog(
                  context: context,
                  barrierDismissible: false,
                  builder: (BuildContext context) {
                    return AlertDialog(
                      title: Center(child: Text('Alert')),
                      content: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          Container(
                            child: Text(
                              "message",
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                color: Colors.red,
                              ),
                            ),
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: <Widget>[
                              FlatButton(
                                  child: Text('Yes'),
                                  onPressed: () {
                                    Navigator.of(context).pop();
                                  }),
                              FlatButton(
                                  child: Text('No'),
                                  onPressed: () {
                                    Navigator.of(context).pop();
                                  })
                            ])
                        ],
                      ),
                    );
                  });
    
        4
  •  0
  •   ibrahimdevs    6 年前

    RFlutter Alert

    var alertStyle = AlertStyle(
        animationType: AnimationType.fromTop,
        isCloseButton: false,
        isOverlayTapDismiss: false,
        descStyle: TextStyle(fontWeight: FontWeight.bold),
        animationDuration: Duration(milliseconds: 400),
        alertBorder: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(0.0),
        side: BorderSide(
            color: Colors.grey,
        ),
        ),
        titleStyle: TextStyle(
        color: Colors.red,
        ),
    );
    

    Alert(
        context: context,
        style: alertStyle,
        type: AlertType.info,
        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),
            color: Color.fromRGBO(0, 179, 134, 1.0),
            radius: BorderRadius.circular(0.0),
        ),
        ],
    ).show();
    

    推荐文章