Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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 自动运行StatefulWidget而不按out On_Flutter - Fatal编程技术网

Flutter 自动运行StatefulWidget而不按out On

Flutter 自动运行StatefulWidget而不按out On,flutter,Flutter,我有下面的代码 onPressed: () { ShowAlert( message: Text, context: context, icon: Icon( Icons.check, ));} 我的ShowAlert class ShowAlert<T> extends Stat

我有下面的代码

        onPressed: () {
            ShowAlert(
                message: Text,
                context: context,
                icon: Icon(
                  Icons.check,
                ));}
我的
ShowAlert

class ShowAlert<T> extends StatefulWidget{
     .....
}
class ShowAlert扩展StatefulWidget{
.....
}
我的意思是当用户按下时,应用程序将显示小警报。 现在,我想警报将自动显示,不按按钮


我该怎么做呢?

创建一个类来显示您的
对话框。例如:将其放入名为Dialog.dart的文件中:

class Dialog{
  static showMyDialog(
    BuildContext context,
  ) async {
    await showDialog(
        context: context,
        barrierDismissible: true,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("title"),
            content: Text("label"),
            actions: <Widget>[
              RaisedButton(
                  onPressed: () => Navigator.pop(context),
                  child: Text(
                    "Action",
                    style: TextStyle(color: Colors.white),
                  )),
            ],
          );
        });
  }
}

基于时间显示?在初始状态下调用代码function@Programmer_3我试过了,但没有成功
  @override
  Widget build(BuildContext context) {
   Dialogs.showMyDialog(context); //add this
   return Scaffold(
   ...
  }