You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1KB

  1. import 'package:farm_tpf/utils/const_color.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:provider/provider.dart';
  4. enum AppThemeStyle { light, dark }
  5. final Map<AppThemeStyle, ThemeData> _themes = {
  6. AppThemeStyle.light: ThemeData(
  7. primaryColor: Colors.green,
  8. accentColor: Colors.green,
  9. brightness: Brightness.light,
  10. ),
  11. AppThemeStyle.dark: ThemeData(
  12. primaryColor: Colors.blue,
  13. accentColor: Colors.blue,
  14. brightness: Brightness.dark,
  15. ),
  16. };
  17. class AppTheme extends ChangeNotifier {
  18. static AppTheme of(BuildContext context, {bool listen = false}) =>
  19. Provider.of<AppTheme>(context, listen: listen);
  20. AppThemeStyle _themeKey = AppThemeStyle.light;
  21. ThemeData get currentTheme => _themes[_themeKey];
  22. AppThemeStyle get currentThemeKey => _themeKey;
  23. void setTheme(AppThemeStyle themeKey) {
  24. _themeKey = themeKey;
  25. notifyListeners();
  26. }
  27. void switchTheme() {
  28. if (_themeKey == AppThemeStyle.dark) {
  29. _themeKey = AppThemeStyle.light;
  30. } else {
  31. _themeKey = AppThemeStyle.dark;
  32. }
  33. notifyListeners();
  34. }
  35. }