void _authKey() {
Hmac hmacSha = new Hmac(sha256, utf8.encode("604ec80ffa552786f409590994dc89cfef040b72"));
String hashValue = "";
List<String> sortedKeys = _datas.keys.toList()..sort();
sortedKeys.forEach((f) => hashValue += _datas[f]! + "+");
print("waw");
SharedPreferences.getInstance().then((prefs) => () {
print("wow");
String? token = prefs.getString('apitoken');
print("the auth key is " + token.toString());
key = hmacSha
.convert(utf8.encode(hashValue + token.toString()))
.toString();
});
}
Why isn’t "wow" printed ? It’s never displayed in the console… But "waw" is…
So why is the SharedPreferences.getInstance().then((prefs) => ()
neved trigged ?
3
Answers
Because you are creating anonymous function
What it should be
you can write like this too
or write like this
Use SharedPrefs Class
**Call init function before runApp **