jancooth
jancooth

Reputation: 567

Flutter - sharedpreferences getString method

I successfuly saved a string to sharedpreferences. But, I dont understand how to getString and use this a parameter llike below code.

My getstring method;

Future<String> getString(String param) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(param) ?? 'lang';

I try to send a string with fetchApps method. This string should comes from sharedpreferences getString method.

return FutureBuilder<List<Apps>>(
        future: fetchApps(getString('lang')),
        builder: (c, s) {
...

Upvotes: 0

Views: 370

Answers (1)

xion
xion

Reputation: 1369

your getString function is a Future You should use await in your getString('lang') like this:

return FutureBuilder<List<Apps>>(
        future: fetchApps(await getString('lang')),
        builder: (c, s) {

Upvotes: 1

Related Questions