我正在使用BLoC跟踪达到网络API端点的状态,并使用此代码根据请求的状态向用户显示一些UI,如团体中emailRequest
流所表示的:
class _LoginScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
LoginInheritedWidget.of(context).bloc.emailRequest.forEach((emailRequest) {
switch (emailRequest.runtimeType) {
case RequestStateInProgress:
showDialog(
context: context,
builder: (BuildContext context) {
return LoadingDialog();
});
break;
case RequestStateSucceeded:
final email = emailRequest.responseData["email"];
Navigator.of(context).pop(); // pop previous in-progress modal dialog
Navigator.pushNamed(context, "/authcode", arguments: email);
break;
case RequestStateFailed:
Navigator.of(context).pop(); // pop previous in-progress modal dialog
showDialog(
context: context,
builder: (BuildContext context) {
return ErrorDialog(message: "Invalid email - please try again");
});
break;
default:
// Dart doesn't have sealed classes :-(
throw new ArgumentError.value(
emailRequest, 'data', 'Unexpected subtype of RequestState');
}
});
return _LoginIdle();
}
}
但是在某些switch
情况下,如果我需要显示以前显示的“进行中” AlertDialog,需要先弹出“我显示错误AlertDialog或导航至”,我对此感到不满意一条不同的路线。
如果有某种方法可以查询导航器以找出AlertDialog是否为尝试pop()
之前的当前路由,那将是很好的,但这似乎不可能-会有另一种方法实现这一目标?