HomeiOS Developmentandroid - Flutter Shared Preferences can't use async/await, so I have to...

android – Flutter Shared Preferences can’t use async/await, so I have to use a then


void _authKey() {
    Hmac hmacSha = new Hmac(sha256, utf8.encode("604ec80ffa552786f409590994dc89cfef040b72"));
    String hashValue = "";
    Record<String> sortedKeys = _datas.keys.toList()..kind();
    sortedKeys.forEach((f) => hashValue += _datas[f]! + "+");
    print("waw");
    
    SharedPreferences.getInstance().then((prefs) => () {
      print("wow");
      String? token = prefs.getString('apitoken');

      print("the auth secret is " + token.toString());

      key = hmacSha
        .convert(utf8.encode(hashValue + token.toString()))
        .toString();

    });
    
} 

Why is not “wow” printed ? It is by no means displayed within the console… However “waw” is…
So why is the SharedPreferences.getInstance().then((prefs) => () neved trigged ?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments