我们希望在一些异步处理(例如网络进程)之后显示一个 AlertDialog。
从外部类调用“showAlertDialog()”时,我想在没有上下文的情况下调用它。有什么好办法吗?
class SplashPage extends StatelessWidget implements SplashView {
BuildContext _context;
@override
Widget build(BuildContext context) {
this._context = context;
...
}
我已经考虑过上述方法,但我担心附带问题。
帮助
我当前的代码
class SplashPage extends StatelessWidget implements SplashView {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: MyStoreColors.eats_white1_ffffff,
body: Center(
child: new SvgPicture.asset('assets/ic_splash.svg'),
),
);
}
@override
void showAlertDialog() {
showDialog<void>(
context: /*How to get context?*/,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Not in stock'),
content: const Text('This item is no longer available'),
actions: <Widget>[
FlatButton(
child: Text('Ok'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
@override
void moveToHomeContainer() {
}
@override
void moveToLoginContainer() {
}
}