【发布时间】:2020-11-18 14:51:51
【问题描述】:
如何在下面的sharedpreference.im共享代码中保存响应标头中传递的令牌:
Future<DriverModel> _handleLogin(Int country_code, Int phone, String password) async {
var jsonData = null;
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
Map data = {
'phone': {
'country_code': country_code,
'phone': phone,
},
'password': password,
};
var body = json.encode(data);
final response = await http.post(
AuthApi.login,
headers: {"Content-Type": "application/json"},
body: body,
);
if (response.statusCode == 200) {
print(response.headers.entries);
return DriverModel.fromJson(jsonData);
} else {
return DriverModel.fromJson(jsonData);
}
}
【问题讨论】:
-
我认为令牌不应该保存在共享首选项中,因为它不安全。为什么不使用pub.dev/packages/flutter_secure_storage?