Skip to content

Instantly share code, notes, and snippets.

@nbnD
Created July 5, 2022 07:09
Show Gist options
  • Save nbnD/111b8b06b8c5dc7f61325c47c35d5cff to your computer and use it in GitHub Desktop.
Save nbnD/111b8b06b8c5dc7f61325c47c35d5cff to your computer and use it in GitHub Desktop.
Theme Switcher
import 'package:flutter/material.dart';
import 'mytheme_preference.dart';
class ModelTheme extends ChangeNotifier {
late bool _isDark;
late MyThemePreferences _preferences;
bool get isDark => _isDark;
ModelTheme() {
_isDark = false;
_preferences = MyThemePreferences();
getPreferences();
}
//Switching the themes
set isDark(bool value) {
_isDark = value;
_preferences.setTheme(value);
notifyListeners();
}
getPreferences() async {
_isDark = await _preferences.getTheme();
notifyListeners();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment