import 'dart:async'; import 'dart:convert'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:tsacdop/class/podcast_group.dart'; class KeyValueStorage { final String key; KeyValueStorage(this.key); Future> getGroups() async { SharedPreferences prefs = await SharedPreferences.getInstance(); if (prefs.getString(key) == null) { PodcastGroup home = PodcastGroup('Home'); await prefs.setString( key, json.encode({ 'groups': [home.toEntity().toJson()] }));} print(prefs.getString(key)); return json .decode(prefs.getString(key))['groups'] .cast>() .map(GroupEntity.fromJson) .toList(growable: false); } Future saveGroup(List groupList) async { SharedPreferences prefs = await SharedPreferences.getInstance(); return prefs.setString( key, json.encode( {'groups': groupList.map((group) => group.toJson()).toList()})); } Future saveTheme(int setting) async{ SharedPreferences prefs = await SharedPreferences.getInstance(); return prefs.setInt(key, setting); } Future getTheme() async{ SharedPreferences prefs = await SharedPreferences.getInstance(); if(prefs.getInt(key) == null) await prefs.setInt(key, 0); return prefs.getInt(key); } Future savePlaylist(List playList) async{ SharedPreferences prefs = await SharedPreferences.getInstance(); return prefs.setStringList(key, playList); } Future> getPlayList() async{ SharedPreferences prefs = await SharedPreferences.getInstance(); if(prefs.getStringList(key) == null) {await prefs.setStringList(key, []);} print(prefs.getStringList(key).toString()); return prefs.getStringList(key); } }