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(
...
}