Answers for "Persist the chosen theme using Shared Preferences"

0

Persist the chosen theme using Shared Preferences

// _initPref() is to iniliaze  the _pref variable
  _initPrefs() async {
    if(_pref == null)
      _pref  = await SharedPreferences.getInstance();
  }
  _loadFromPrefs() async {
      await _initPrefs();
      _darkTheme = _pref.getBool(key) ?? true;
      notifyListeners();
  }
  _saveToPrefs() async {
    await _initPrefs();
    _pref.setBool(key, _darkTheme);
  }
Posted by: Guest on July-24-2021

Code answers related to "Persist the chosen theme using Shared Preferences"

Browse Popular Code Answers by Language