Clean Architecture structure: - core/config - Environment configuration - core/theme - Material 3 theming with FlexColorScheme - core/error - Typed exception hierarchy - core/api - Dio HTTP clients with interceptors - core/auth - Authentication state management - routing - go_router with shell navigation - shared/layouts - Adaptive scaffold Dependencies added: - flutter_riverpod, riverpod_annotation, riverpod_generator - freezed, freezed_annotation, json_serializable - dio, go_router, shared_preferences - flex_color_scheme, flutter_adaptive_scaffold Features: - Responsive navigation (rail on desktop, bottom on mobile) - Dashboard placeholder with welcome card - Theme switching infrastructure - API client ready for Core API and Tatlock API 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
56 lines
1.4 KiB
Dart
56 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
part 'theme_provider.g.dart';
|
|
|
|
/// User's theme preference setting.
|
|
enum ThemeSetting {
|
|
/// Follow system preference
|
|
system,
|
|
|
|
/// Always light mode
|
|
light,
|
|
|
|
/// Always dark mode
|
|
dark,
|
|
}
|
|
|
|
/// Provider for theme setting state.
|
|
@riverpod
|
|
class ThemeNotifier extends _$ThemeNotifier {
|
|
static const _prefsKey = 'theme_setting';
|
|
|
|
@override
|
|
ThemeSetting build() {
|
|
_loadSavedSetting();
|
|
return ThemeSetting.system;
|
|
}
|
|
|
|
Future<void> _loadSavedSetting() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final value = prefs.getString(_prefsKey);
|
|
if (value != null) {
|
|
try {
|
|
state = ThemeSetting.values.byName(value);
|
|
} catch (_) {
|
|
// Invalid value, keep default
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Update theme setting and persist to storage.
|
|
Future<void> setSetting(ThemeSetting setting) async {
|
|
state = setting;
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString(_prefsKey, setting.name);
|
|
}
|
|
|
|
/// Get the ThemeMode for MaterialApp.
|
|
ThemeMode get themeMode => switch (state) {
|
|
ThemeSetting.system => ThemeMode.system,
|
|
ThemeSetting.light => ThemeMode.light,
|
|
ThemeSetting.dark => ThemeMode.dark,
|
|
};
|
|
}
|