简体   繁体   中英

How to store multiple variables locally in Flutter App

I want to make an app with n different quizzes. When restarting the app I want the users last score to be shown for the n quizzes. How do I do that?

I have seen examples when one store a single variable. But I do not know how to make it work when one wants to store multiple values/strings locally.

It is possible to store an array if you JsonEncode it first.

List dailygoals = ['apple', 'banana'];
SharedPreferences prefs = await SharedPreferences.getInstance();
dailygoals.add('orange');
prefs.setString('dailygoals', jsonEncode(dailygoals));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM