Hello there, Sandor.

Without looking at your code, here’s one guess. With the ‘SharedPreference’ capability, as you know, we’re dealing with a ‘Future’. You’re getting that exception because your calling for an instance of ‘SharedPreference’ to get you a preference when it literally hasn’t had time to instantiate. In other words, you’ve chosen to call for the ‘weeklyLimit’ preference right in the initState() function. Again, without knowing your situation, I would suggest changing the instance variable, limit, to a Future or assign the variable, limit, elsewhere where, by then, the SharedPrefence has had time to instantiate.

Future<int> limit;
void initState() {
this.limit = Prefs.getIntF("weeklyLimit");

Ray Li also recognized this problem — dealing with the asynchronous nature of SharedPreference. In his case, using the ‘Future version’ of a get function seemed the solution.



Freelance Developer

Freelance Developer