0

I saved SharedPreference value and I need to get saved value from every class.

getUrlPreference method

Future<String> getUrlPreferences() async {
  SharedPreferences pref = await SharedPreferences.getInstance();
  String url = pref.getString("url");
  return url;
}

I need to get url from here.

usernameValidation(usernameTextField){
  String urls;
  getUrlPreferences().then((url)=> urls = url);
  print(urls);
}

But result is null

I Used this way, I can get saved value. How to assign to variable?

usernameValidation(usernameTextField){
  getUrlPreferences().then((url)=> print(url));
}
1

1 Answer 1

1
usernameValidation(usernameTextField){
  getUrlPreferences().then((url)=> print(url));
}

If you succeeded this way, you can try assign like this:

     usernameValidation(usernameTextField){
          getUrlPreferences().then((url) {
    getUrl = url;
    print(getUrl);
    });
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.