Files
AppRecoleccion/celaya_limpia/lib/services/theme_service.dart

25 lines
796 B
Dart

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ThemeService extends ChangeNotifier {
ThemeMode _themeMode = ThemeMode.light;
ThemeMode get themeMode => _themeMode;
bool get isDark => _themeMode == ThemeMode.dark;
ThemeService() { _load(); }
Future<void> _load() async {
final p = await SharedPreferences.getInstance();
final isDark = p.getBool('dark_mode') ?? false;
_themeMode = isDark ? ThemeMode.dark : ThemeMode.light;
notifyListeners();
}
Future<void> toggle() async {
_themeMode = _themeMode == ThemeMode.dark ? ThemeMode.light : ThemeMode.dark;
final p = await SharedPreferences.getInstance();
await p.setBool('dark_mode', _themeMode == ThemeMode.dark);
notifyListeners();
}
}