当我在登录块中调用 flutter 安全存储时,我的应用程序卡住了

问题描述

我在我的登录块中使用 Flutter_secure_storage 包来在登录后安全地保存用户数据。然而,处理在调用 secure_storage 来存储数据时卡住了。在服务器上登录工作正常。当我再次注释掉本地存储代码时,线程工作正常。

这是在我的登录

...
else if (event is LoginSubmitted) {
      yield state.copyWith(appStatus: Submitting()); //show loading icon
//make API request to node server
try{
 final response = await authRepo.signIn(userName: state.userName,password: state.password);
 final responseCode = response.statusCode;
if (responseCode == 200) {
          var responseJson = json.decode(response.body);
          //print(responseJson); //reponse json prints in the console
          usermodel = usermodel.fromJson(responseJson);
//store user data locally securely. This where am getting blocked.
await UserSecureStorage.setToken(user.data.token);
 await UserSecureStorage.setUserId(user.data.user.id);
...
      yield state.copyWith(appStatus: Success());


}

}

UserSecureStorage 类

import 'dart:async';
import 'package:Flutter_secure_storage/Flutter_secure_storage.dart';

class UserSecureStorage {
  static final _storage = FlutterSecureStorage();
  
  static Future setToken(String token) async {
    return await _storage.write(key: 'token',value: token);
  }

  static Future getToken() async {
    final token = await _storage.read(key: 'token');
    return token;
  }

  static Future setUserId(String id) async {
    return await _storage.write(key: 'userId',value: id);
  }

  static Future getUserId() async {
    final id = await _storage.read(key: 'userId');
    return id;
  }

  

  static Future setUserName(String userName) async {
    return await _storage.write(key: 'username',value: 'userName');
  }

  static Future getUserName() async {
    final username= await _storage.read(key: 'userName');
    return username;
  }
}

请求堆栈在 ***await

UserSecureStorage.setToken(user.data.token);...

登录区。我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)