How can I get out of an "Asynchronous programming"-loop? Do I need to write every method that is using on-device-values as Future?
I can call addPassword() from outside, but still have to wait, until it is set (Future function). I just want to return those values like any other method.
My attempt:
How I store values on the device:
import 'package:shared_preferences/shared_preferences.dart';
class StorageConnector {
static Future setInt(String key, int value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.setInt(key, value);
}
static Future getInt(String key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getInt(key);
}
}
How I receive the previously written values from the device:
class Account{
void addPassword(int password){ //i dont want to use await/async, because of this later functions
StorageConnector.setInt("passwords", password);
}
int getAtPassword(int pos) { //Attention: doesn't compile
/* I have tried this: */
StorageConnector.getInt("passwords").then((value) { return value;});
/* and this: */
return StorageConnector.getInt("passwords");
}
}
There are similar questions, but unfortunately, I was not able to understand/apply them properly.
Similiar: FutureBuilder, .then(function), external functions