有什么方法可以使扑朔迷离的警报对话成为一个普通的课堂?

时间:2020-01-15 06:17:52

标签: flutter-layout

是否可以使一个普通的班级在扑朔迷离中显示弹出窗口(警报对话框)。如果是这样,请帮我举个例子。

2 个答案:

答案 0 :(得分:1)

创建popups.dart

在您的popups.dart内部

void showYourPopUp(context){
  showDialog(
    context: context,
    builder: (_)=> AlertDialog(
      backgroundColor: Colors.transparent,
      content: BackdropFilter(
        filter: ImageFilter.blur(sigmaX: 4.0,sigmaY:4.0) //this is for background blur only you can remove BackdropFilter if you want
       child: *your popup design*
      )
    )
  );
}

然后在您要使用的类中导入popups.dart,例如

这是您的main.dart

导入“ your_app / popups.dart”

使用方法:

GestureDetector(
  onTap(){
    showYourPopUp(context);
  }
)

答案 1 :(得分:0)

这是您可以使用的对话框类-DeleteHomeDialog将是常见的类

onTap: (){
    showDeleteDialog();
}

 showDeleteDialog() {
    showDialog(
      context: context,
      builder: (BuildContext context) =>
          DeleteHomeDialog(),
    );
  }

class DeleteHomeDialog extends StatelessWidget {
  DeleteHomeDialog();

  @override
  Widget build(BuildContext context) {

    dialogContent(BuildContext context) {
      return Stack(
        children: <Widget>[
          Container(
            padding: EdgeInsets.fromLTRB(10, 15, 10, 10),
            margin: EdgeInsets.only(top: 10),
            decoration: new BoxDecoration(
              color: Colors.white,
              shape: BoxShape.rectangle,
              borderRadius: BorderRadius.circular(10),
              boxShadow: [
                BoxShadow(
                  color: Colors.black26,
                  blurRadius: 10.0,
                  offset: const Offset(0.0, 10.0),
                ),
              ],
            ),
            child: new Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Text("Alert", style: TextStyle(color: Colors.red, fontSize: 18, fontWeight: FontWeight.bold),),
                Container(margin: EdgeInsets.fromLTRB(10, 15, 10, 0),
                  child: Text("Are you sure you want to delete ?", style: TextStyle(color: Colors.red, fontSize: 18),),
                ),
                Container(
                  margin: EdgeInsets.all(20),
                  child: RaisedButton(
                    child: Text("Cancel"),
                    onPressed: () {
                      Navigator.pop(context);
                    },
                    color: Colors.red,
                    textColor: Colors.white,
                    padding: EdgeInsets.fromLTRB(20, 12, 20, 12),
                    splashColor:Colors.red,
                    shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
                  ),
                )
              ],
            ),
          )
        ],
      );
    }

    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10),
      ),
      elevation: 0.0,
      backgroundColor: Colors.transparent,
      child: dialogContent(context),
    );
  }
}
相关问题