Skip to content

Instantly share code, notes, and snippets.

@nbnD
Created July 5, 2022 07:05
Show Gist options
  • Save nbnD/97e0c4ce6f8c41a2c20affb5287cb440 to your computer and use it in GitHub Desktop.
Save nbnD/97e0c4ce6f8c41a2c20affb5287cb440 to your computer and use it in GitHub Desktop.
Theme Switcher
import 'package:shared_preferences/shared_preferences.dart';
class MyThemePreferences {
static const THEME_KEY = "theme_key";
setTheme(bool value) async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
sharedPreferences.setBool(THEME_KEY, value);
}
getTheme() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
return sharedPreferences.getBool(THEME_KEY) ?? false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment