[英]Flutter Secure Storage
如何從FutureBuilder中未提供的任何其他功能中從安全存儲中獲取數據。
Future<void> login() async {
print('LOGGGGINNNNNNNNNNNN');
print(read('TOKEN'));
}
Future read(String storageName) async {
return await _storage.read(key: storageName);
}
打印結果:“未來”實例
你應該這樣做
Future<void> login() async {
print('LOGGGGINNNNNNNNNNNN');
print(await read('TOKEN'));
}
Future read(String storageName) async {
return _storage.read(key: storageName);
}
由於read
返回Future,它將打印您當前看到的內容,因此您需要等待其完成。
解
Future readStorage(String storageName) async {
return await _storage.read(key: storageName);
}
Future getToken() async {
final _storage = new FlutterSecureStorage();
await Future.sync(() async => _token = await _storage.read(key: 'TOKEN'));
}
Future<void> login() async {
getToken().then((value){
print(_token);
if(_token == 'Not Authenticated' || _token == null)
{
setState(() {
_isAuthenticated = false;
});
}
else {
setState(() {
_isAuthenticated = true;
});
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.