flutter - 未处理的异常:类型“FlutterError”不是类型转换中“异常”类型的子类型
问题描述
在使用 Flutter 成功登录后,我试图将用户重定向到主屏幕,但我最终得到了错误,并且返回到登录页面没有被重定向。
未处理的异常:类型“FlutterError”不是类型转换中“异常”类型的子类型
到目前为止我做了什么
我的登录功能
handleSignIn() async {
await msal.signIn(null, [SCOPE]).then((result) {
Navigator.push(context, MaterialPageRoute(builder: (context)=> Home()));
refreshSignedInStatus();
}).catchError((exception) {
if (exception is MsalMobileException) {
logMsalMobileError(exception);
} else {
final ex = exception as Exception;
print('exception occurred');
print(ex.toString());
}
});
}
更新登录状态
refreshSignedInStatus() {
msal.getSignedIn().then((loggedIn) {
print('refreshing');
setState(() {
isSignedIn = loggedIn;
});
});
}
处理按钮上的onclick
Text(' Sign in', style: TextStyle( color: Colors.black, fontSize: 18.0),
),
],
),
onPressed: handleSignIn,
),
)),
我做错了什么,提前感谢您的帮助
解决方案
你在这里不需要 TypeCasting
final ex = exception as Exception;
此语法会导致错误
您可以简单地将异常分配给变量(不推荐),也可以直接使用该变量(推荐)。
推荐阅读
- python-3.x - 一个函数参数可以有多个默认值吗?
- mysql - sqlMessage:“用户'user@host'的访问被拒绝(使用密码:是)”
- c - 使用scanf时c中的不同数组声明
- typescript - 从 Typescript 中的元组推断函数签名
- c - 使用 __int128 表示大数
- java - 如何在 Maven 中使用单个 groupId 和多个 artifactId?
- react-native - 反应支持用户onPress的本机图表/图形库?
- java - Android Studio 错误:javaFXPlugin 已使用更新版本编译
- python - 声明后数据无效 - Kivy
- google-apps-script - Google App Script 插入新工作表并追加列