Files
sure/mobile/lib/providers/theme_provider.dart
Tristan Katana b1fd8bbc99 Mobile: Add theme selection (light/dark/system) to settings (#1213)
* Feature: Add Theme selection in Settings page

* Fix: Theme provider exception handling.

* feat(mobile): Show theme selection option in settings screen.

* BuildID version 9

---------

Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
2026-03-26 22:47:31 +01:00

51 lines
1.1 KiB
Dart

import 'package:flutter/material.dart';
import '../services/preferences_service.dart';
class ThemeProvider extends ChangeNotifier {
ThemeMode _themeMode = ThemeMode.system;
ThemeMode get themeMode => _themeMode;
ThemeProvider() {
_loadThemeMode();
}
Future<void> _loadThemeMode() async {
try {
final mode = await PreferencesService.instance.getThemeMode();
_themeMode = _fromString(mode);
} catch (_) {
_themeMode = ThemeMode.system;
}
notifyListeners();
}
Future<void> setThemeMode(ThemeMode mode) async {
_themeMode = mode;
notifyListeners();
await PreferencesService.instance.setThemeMode(_toString(mode));
}
static ThemeMode _fromString(String mode) {
switch (mode) {
case 'light':
return ThemeMode.light;
case 'dark':
return ThemeMode.dark;
default:
return ThemeMode.system;
}
}
static String _toString(ThemeMode mode) {
switch (mode) {
case ThemeMode.light:
return 'light';
case ThemeMode.dark:
return 'dark';
case ThemeMode.system:
return 'system';
}
}
}