123456789101112131415161718192021222324252627 |
- import 'package:flutter/material.dart';
- import 'package:riverpod/riverpod.dart';
- final themeProvider = StateNotifierProvider<ThemeNotifier, ThemeMode>((ref) {
- return ThemeNotifier();
- });
- class ThemeNotifier extends StateNotifier<ThemeMode> {
-
- ThemeNotifier() : super(ThemeMode.system);
-
- void toggleTheme() {
- if (state == ThemeMode.light) {
- state = ThemeMode.dark;
- } else if (state == ThemeMode.dark) {
- state = ThemeMode.light;
- } else {
- state = ThemeMode.light;
- }
- }
-
- void followSystemTheme() {
- state = ThemeMode.system;
- }
- }
|