小编New*_*per的帖子

如何禁止用户在flutter中成功登录后返回

我有这个登录功能,它的工作方式就像 charm ,但是用户可以按后退按钮并返回登录屏幕的问题,我想禁用它。

void _login() async {
setState(() {
  _isLoading = true;
});
var data = {'email': email, 'password': password};
print("Data =" + data.toString());
var res = await Network().authData(data, '/login');
var body = json.decode(res.body);
print(body);
if (body['success']) {
  SharedPreferences localStorage = await SharedPreferences.getInstance();
  localStorage.setString('access_token', json.encode(body['access_token']));
  localStorage.setString('user', json.encode(body['user']));
  if (body['user']['verified'] == 1) {
  // OPEN THE HOME PAGE AND BLOCK THE BACK ACTION 
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => HomeScreen()),
    );
  } else {
    showAnimatedDialog(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) …
Run Code Online (Sandbox Code Playgroud)

dart flutter

1
推荐指数
1
解决办法
1708
查看次数

标签 统计

dart ×1

flutter ×1