我试图从类的getter方法中获取保存在SharedPreferences
中的一些值。但是SharedPreferences.getInstance()
返回一个Future
。有没有一种方法可以在非async
getter方法中获取SharedPreferences
对象,例如:
import 'package:shared_preferences/shared_preferences.dart';
class MyClass {
get someValue {
return _sharedPreferencesObject.getString("someKey");
}
}
Dart 中是否有类似 C# 的 .Result
属性的东西,例如 getSomethingAsync().Result
?(https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1.result?view=netframework-4.7.2)
FutureBuilder
https://stackoverflow.com/questions/54634418/how-to-properly-wait-until-future-is-complete-in-dart/54634695#54634695 - Mazin Ibrahim