import 'package:shared_preferences/shared_preferences.dart'; import 'package:fcs/vo/report.dart'; import 'dart:convert'; import 'package:fcs/vo/user.dart'; class SharedPref { static final SharedPref instance = SharedPref._(); SharedPref._(); static Future getLang() async { SharedPreferences prefs = await SharedPreferences.getInstance(); return prefs.getString('language'); } static Future saveLang(String lang) async { SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setString('language', lang); } static Future saveUser(User user) async { await _save("user", user.toJson()); } static Future saveReport(ReportFieldPositionSelection report) async { await _save('report-${report.id}', report.toJson()); } static Future getReport(String id) async { try { return ReportFieldPositionSelection.fromJson(await _read("report-$id")); } catch (e) { return null; } } static Future getUser() async { try { return User.fromJson(await _read("user")); } catch (e) { return null; } } static Future removeUser() async { return await _remove("user"); } static Future saveSkippedRecoverEmail(bool skipped) async { await _save("skipped_recovery_email", skipped); } static Future getSkippedRecoverEmail() async { try { bool _skipped = await _read("skipped_recovery_email"); return _skipped; } catch (e) { return null; } } static _read(String key) async { try { final prefs = await SharedPreferences.getInstance(); return json.decode(prefs.getString(key)); } catch (e) { print("Error:$e"); } } static _save(String key, value) async { try { final prefs = await SharedPreferences.getInstance(); prefs.setString(key, json.encode(value)); } catch (e) { print("Error:$e"); } } static _remove(String key) async { final prefs = await SharedPreferences.getInstance(); prefs.remove(key); } }