I am trying to get some values saved in the SharedPreferences
from a getter method of a class. But SharedPreferences.getInstance()
returns a Futu
You can use FutureBuilder()
SharedPreferences sharedPrefs;
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _getPrefs(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return YourFinalWidget();
}
return CircularProgressIndicator(); // or some other widget
},
);
}
Future _getPrefs() async{
sharedPrefs = await SharedPreferences.getInstance();
}