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 _load() async { final p = await SharedPreferences.getInstance(); final isDark = p.getBool('dark_mode') ?? false; _themeMode = isDark ? ThemeMode.dark : ThemeMode.light; notifyListeners(); } Future toggle() async { _themeMode = _themeMode == ThemeMode.dark ? ThemeMode.light : ThemeMode.dark; final p = await SharedPreferences.getInstance(); await p.setBool('dark_mode', _themeMode == ThemeMode.dark); notifyListeners(); } }