我想在我的 flutter 应用程序中实现注销功能。我的侧边菜单抽屉注销中有一个按钮,当用户按下按钮时,我希望用户导航到登录屏幕并弹出所有其他屏幕。
我试过这样做,我的代码是
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.remove('userPreference');
await Future.delayed(Duration(seconds: 2));
Navigator.of(context)
.popUntil(ModalRoute.withName(Navigator.defaultRouteName));
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (BuildContext context) =>
LoginScreen(),
)
);
Run Code Online (Sandbox Code Playgroud)