Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class HomePageData {
Future saveJsonData(jsonData) async {
final prefs = await SharedPreferences.getInstance();
var saveData = jsonEncode(jsonData);
await prefs.setString('jsonData', saveData);
}
Future<void> getJsonData() async {
final prefs = await SharedPreferences.getInstance();
var temp = prefs.getString('jsonData') ?? jsonEncode(defaultData);
debugPrint('Data received: $temp');
var data = HomePageModel.fromMap(jsonDecode(temp.toString()));
debugPrint('Name: ${(data.name.toString())}');
debugPrint('Age: ${(data.age.toString())}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment