httpErrorHandle(
response: res,
context: context,
onSuccess: () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
Provider.of<UserProvider>(context, listen: false).setUser(res.body);
await prefs.setString('x-auth-token', jsonDecode(res.body)['token']);
Navigator.pushNamedAndRemoveUntil(
context,
HomeScreen.routeName,
(route) => false,
);
},
);
我没有找到任何相关的解决方案,这段代码正在破坏应用程序
httpErrorHandle(
response: res,
context: context,
onSuccess: () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
Provider.of<UserProvider>(context, listen: false).setUser(res.body);
await prefs.setString('x-auth-token', jsonDecode(res.body)['token']);
//if you are using a statefulWidget do:
if(!mounted) return;
//if it is a statelessWidget do:
if(!context.mounted) return;
Navigator.pushNamedAndRemoveUntil(
context,
HomeScreen.routeName,
(route) => false,
);
},
);