Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b6614f482 | ||
|
|
265ca5959d | ||
|
|
c617d7dfbb | ||
|
|
f0f5e08c46 | ||
|
|
9db677bee2 |
@@ -7,6 +7,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.1.15] - 2026-01-05
|
||||
|
||||
### Fixed
|
||||
- Theme toggle causing auth issues due to AuthNotifier auto-dispose
|
||||
- Applied `@persistentRiverpod` annotation to AuthNotifier
|
||||
- AuthProvider now persists for app lifetime, preventing rebuild on theme change
|
||||
|
||||
## [1.1.14] - 2026-01-04
|
||||
|
||||
### Fixed
|
||||
- Theme toggle causing auth issues due to ThemeProvider auto-dispose
|
||||
- Added `@persistentRiverpod` annotation for providers that need keepAlive
|
||||
- ThemeProvider now persists for app lifetime
|
||||
|
||||
### Added
|
||||
- `@persistentRiverpod` annotation in `core/providers/annotations.dart`
|
||||
- Reusable annotation for providers that should not auto-dispose
|
||||
- Documented in ARCHITECTURE.md
|
||||
|
||||
## [1.1.13] - 2026-01-04
|
||||
|
||||
### Added
|
||||
- Settings page with Appearance, Navigation, and Account sections
|
||||
- Theme toggle in user profile dropdown (System/Light/Dark)
|
||||
- Theme syncs with API preferences on login
|
||||
- Default room preference syncs with backend
|
||||
|
||||
### Changed
|
||||
- Theme changes now persist to both local storage and API
|
||||
|
||||
## [1.1.12] - 2026-01-04
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -420,6 +420,41 @@ ContainerRepository containerRepository(Ref ref) {
|
||||
}
|
||||
```
|
||||
|
||||
### Persistent Providers
|
||||
|
||||
By default, `@riverpod` generates providers with `isAutoDispose: true`, meaning they dispose when no longer watched. This causes issues for:
|
||||
|
||||
- **API clients** with interceptors that store a `Ref`
|
||||
- **App-level state** like theme, auth, config
|
||||
- **Providers with listeners** to other providers
|
||||
|
||||
Use `@persistentRiverpod` from `core/providers/annotations.dart` for these cases:
|
||||
|
||||
```dart
|
||||
import 'package:tatlock_ui/core/providers/annotations.dart';
|
||||
|
||||
// ✅ Correct - persists for app lifetime
|
||||
@persistentRiverpod
|
||||
Dio coreApiClient(Ref ref) { ... }
|
||||
|
||||
@persistentRiverpod
|
||||
class ThemeNotifier extends _$ThemeNotifier { ... }
|
||||
|
||||
// ❌ Wrong - auto-dispose can invalidate stored Ref
|
||||
@riverpod
|
||||
Dio coreApiClient(Ref ref) { ... }
|
||||
```
|
||||
|
||||
**When to use `@persistentRiverpod`:**
|
||||
|
||||
| Use Case | Annotation | Example |
|
||||
|----------|------------|---------|
|
||||
| API clients with interceptors | `@persistentRiverpod` | `coreApiClient`, `tatlockApiClient` |
|
||||
| Auth state provider | `@persistentRiverpod` | `AuthNotifier` |
|
||||
| Theme/config providers | `@persistentRiverpod` | `ThemeNotifier` |
|
||||
| Feature data providers | `@riverpod` (default) | `ContainersNotifier` |
|
||||
| UI state providers | `@riverpod` (default) | `SearchFilterNotifier` |
|
||||
|
||||
## File Naming Conventions
|
||||
|
||||
| Type | Convention | Example |
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:dio/dio.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:tatlock_ui/core/api/api_interceptors.dart';
|
||||
import 'package:tatlock_ui/core/config/app_config.dart';
|
||||
import 'package:tatlock_ui/core/providers/annotations.dart';
|
||||
|
||||
import 'api_client_native.dart' if (dart.library.html) 'api_client_web.dart'
|
||||
as platform;
|
||||
@@ -9,10 +10,7 @@ import 'api_client_native.dart' if (dart.library.html) 'api_client_web.dart'
|
||||
part 'api_client.g.dart';
|
||||
|
||||
/// Provides the Dio instance for Core API.
|
||||
///
|
||||
/// Uses keepAlive to prevent auto-dispose - the AuthInterceptor stores
|
||||
/// a Ref that must remain valid for the lifetime of API requests.
|
||||
@Riverpod(keepAlive: true)
|
||||
@persistentRiverpod
|
||||
Dio coreApiClient(Ref ref) {
|
||||
final options = BaseOptions(
|
||||
baseUrl: AppConfig.coreApiUrl,
|
||||
@@ -36,10 +34,7 @@ Dio coreApiClient(Ref ref) {
|
||||
}
|
||||
|
||||
/// Provides the Dio instance for Tatlock API.
|
||||
///
|
||||
/// Uses keepAlive to prevent auto-dispose - the AuthInterceptor stores
|
||||
/// a Ref that must remain valid for the lifetime of API requests.
|
||||
@Riverpod(keepAlive: true)
|
||||
@persistentRiverpod
|
||||
Dio tatlockApiClient(Ref ref) {
|
||||
final options = BaseOptions(
|
||||
baseUrl: AppConfig.tatlockApiUrl,
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../config/app_config.dart';
|
||||
import '../providers/annotations.dart';
|
||||
import 'auth_datasource.dart';
|
||||
import 'auth_state.dart';
|
||||
import 'oidc_service.dart';
|
||||
@@ -24,7 +25,7 @@ part 'auth_provider.g.dart';
|
||||
///
|
||||
/// After OIDC authentication, syncs with core-api via POST /auth/sync
|
||||
/// to get user profile, roles, and preferences.
|
||||
@riverpod
|
||||
@persistentRiverpod
|
||||
class AuthNotifier extends _$AuthNotifier {
|
||||
// Storage keys
|
||||
static const _accessTokenKey = 'auth_access_token';
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
/// Riverpod annotation for providers that should persist for the app lifetime.
|
||||
///
|
||||
/// Use this instead of `@riverpod` when:
|
||||
/// - The provider holds app-level state (theme, auth, config)
|
||||
/// - The provider stores a Ref that must remain valid (API clients with interceptors)
|
||||
/// - Disposing would cause flickering or re-initialization issues
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// @persistentRiverpod
|
||||
/// class ThemeNotifier extends _$ThemeNotifier { ... }
|
||||
/// ```
|
||||
const persistentRiverpod = Riverpod(keepAlive: true);
|
||||
@@ -1,6 +1,10 @@
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tatlock_ui/core/auth/auth_provider.dart';
|
||||
import 'package:tatlock_ui/core/providers/annotations.dart';
|
||||
|
||||
part 'theme_provider.g.dart';
|
||||
|
||||
@@ -17,13 +21,21 @@ enum ThemeSetting {
|
||||
}
|
||||
|
||||
/// Provider for theme setting state.
|
||||
@riverpod
|
||||
///
|
||||
/// Syncs with API preferences when user is authenticated. On login, the theme
|
||||
/// from API preferences takes precedence over local storage.
|
||||
@persistentRiverpod
|
||||
class ThemeNotifier extends _$ThemeNotifier {
|
||||
static const _prefsKey = 'theme_setting';
|
||||
|
||||
@override
|
||||
ThemeSetting build() {
|
||||
// Load local setting first for immediate UI
|
||||
_loadSavedSetting();
|
||||
|
||||
// Listen for auth state changes to sync from API preferences
|
||||
_syncFromAuthPreferences();
|
||||
|
||||
return ThemeSetting.system;
|
||||
}
|
||||
|
||||
@@ -39,6 +51,36 @@ class ThemeNotifier extends _$ThemeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Listen to auth state and sync theme from API preferences.
|
||||
void _syncFromAuthPreferences() {
|
||||
ref.listen(authProvider, (_, next) {
|
||||
next.whenData((auth) {
|
||||
final apiTheme = auth.preferences?.theme;
|
||||
if (apiTheme != null && apiTheme.isNotEmpty) {
|
||||
try {
|
||||
final themeSetting = ThemeSetting.values.byName(apiTheme);
|
||||
if (themeSetting != state) {
|
||||
developer.log(
|
||||
'Syncing theme from API: $apiTheme',
|
||||
name: 'theme',
|
||||
);
|
||||
state = themeSetting;
|
||||
// Also persist to local storage for offline use
|
||||
_saveToLocalStorage(themeSetting);
|
||||
}
|
||||
} catch (_) {
|
||||
// Invalid theme value from API, keep current
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _saveToLocalStorage(ThemeSetting setting) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_prefsKey, setting.name);
|
||||
}
|
||||
|
||||
/// Update theme setting and persist to storage.
|
||||
Future<void> setSetting(ThemeSetting setting) async {
|
||||
state = setting;
|
||||
|
||||
@@ -19,9 +19,9 @@ abstract class ControlRoomRoutes {
|
||||
|
||||
/// Control Room navigation items with section grouping.
|
||||
enum ControlRoomNav {
|
||||
// Stack section - Docker containers and reverse proxy
|
||||
containers('containers', 'Containers', Icons.dns, 'Stack'),
|
||||
proxyHosts('proxy-hosts', 'Proxy Hosts', Icons.public, 'Stack'),
|
||||
// Stack Management section - Docker containers and reverse proxy
|
||||
containers('containers', 'Containers', Icons.dns, 'Stack Management'),
|
||||
proxyHosts('proxy-hosts', 'Proxy Hosts', Icons.public, 'Stack Management'),
|
||||
// Data Management section - Database browsers
|
||||
postgres('postgres', 'PostgreSQL', Icons.table_chart, 'Data Management'),
|
||||
redis('redis', 'Redis', Icons.memory, 'Data Management'),
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:tatlock_ui/core/auth/auth_provider.dart';
|
||||
import 'package:tatlock_ui/core/theme/theme_provider.dart';
|
||||
|
||||
/// Settings page with user preferences.
|
||||
class SettingsPage extends ConsumerWidget {
|
||||
const SettingsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final authState = ref.watch(authProvider);
|
||||
final currentTheme = ref.watch(themeProvider);
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
|
||||
return Scaffold(
|
||||
body: authState.when(
|
||||
data: (auth) => SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 600),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Page header
|
||||
Text(
|
||||
'Settings',
|
||||
style: textTheme.headlineMedium,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// Appearance section
|
||||
_SectionHeader(title: 'Appearance'),
|
||||
const SizedBox(height: 8),
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
_themeIcon(currentTheme),
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Theme', style: textTheme.titleMedium),
|
||||
Text(
|
||||
'Choose your preferred color scheme',
|
||||
style: textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
DropdownButton<ThemeSetting>(
|
||||
value: currentTheme,
|
||||
underline: const SizedBox(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
_updateTheme(ref, value);
|
||||
}
|
||||
},
|
||||
items: const [
|
||||
DropdownMenuItem(
|
||||
value: ThemeSetting.system,
|
||||
child: Text('System'),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: ThemeSetting.light,
|
||||
child: Text('Light'),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: ThemeSetting.dark,
|
||||
child: Text('Dark'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Navigation section
|
||||
_SectionHeader(title: 'Navigation'),
|
||||
const SizedBox(height: 8),
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.home_outlined,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Default Room',
|
||||
style: textTheme.titleMedium,
|
||||
),
|
||||
Text(
|
||||
'Room to show when app opens',
|
||||
style: textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
DropdownButton<String>(
|
||||
value:
|
||||
auth.preferences?.defaultRoom ?? 'front-hall',
|
||||
underline: const SizedBox(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
_updateDefaultRoom(ref, value);
|
||||
}
|
||||
},
|
||||
items: const [
|
||||
DropdownMenuItem(
|
||||
value: 'front-hall',
|
||||
child: Text('Front Hall'),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'control-room',
|
||||
child: Text('Control Room'),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'parlor',
|
||||
child: Text('Parlor'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Account section
|
||||
_SectionHeader(title: 'Account'),
|
||||
const SizedBox(height: 8),
|
||||
Card(
|
||||
child: Column(
|
||||
children: [
|
||||
_AccountInfoTile(
|
||||
icon: Icons.person_outline,
|
||||
label: 'Name',
|
||||
value: auth.userName ?? 'Not available',
|
||||
),
|
||||
const Divider(height: 1),
|
||||
_AccountInfoTile(
|
||||
icon: Icons.email_outlined,
|
||||
label: 'Email',
|
||||
value: auth.userEmail ?? 'Not available',
|
||||
),
|
||||
if (auth.roles.isNotEmpty) ...[
|
||||
const Divider(height: 1),
|
||||
_AccountInfoTile(
|
||||
icon: Icons.shield_outlined,
|
||||
label: 'Roles',
|
||||
value: auth.roles.map((r) => r.name).join(', '),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, _) => Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 48, color: colorScheme.error),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Failed to load settings',
|
||||
style: textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
error.toString(),
|
||||
style: textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
IconData _themeIcon(ThemeSetting theme) {
|
||||
return switch (theme) {
|
||||
ThemeSetting.system => Icons.brightness_auto,
|
||||
ThemeSetting.light => Icons.light_mode,
|
||||
ThemeSetting.dark => Icons.dark_mode,
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> _updateTheme(WidgetRef ref, ThemeSetting setting) async {
|
||||
// Update local theme immediately for instant UI response
|
||||
await ref.read(themeProvider.notifier).setSetting(setting);
|
||||
|
||||
// Sync to backend
|
||||
try {
|
||||
await ref.read(authProvider.notifier).updatePreferences(
|
||||
theme: setting.name,
|
||||
);
|
||||
} catch (e) {
|
||||
developer.log('Failed to sync theme preference: $e', name: 'settings');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _updateDefaultRoom(WidgetRef ref, String room) async {
|
||||
try {
|
||||
await ref.read(authProvider.notifier).updatePreferences(
|
||||
defaultRoom: room,
|
||||
);
|
||||
} catch (e) {
|
||||
developer.log('Failed to sync default room: $e', name: 'settings');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Section header widget.
|
||||
class _SectionHeader extends StatelessWidget {
|
||||
const _SectionHeader({required this.title});
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
|
||||
return Text(
|
||||
title.toUpperCase(),
|
||||
style: textTheme.labelMedium?.copyWith(
|
||||
color: colorScheme.primary,
|
||||
letterSpacing: 1.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Account info tile widget.
|
||||
class _AccountInfoTile extends StatelessWidget {
|
||||
const _AccountInfoTile({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, color: colorScheme.onSurfaceVariant),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
)),
|
||||
const SizedBox(height: 2),
|
||||
Text(value, style: textTheme.titleMedium),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:tatlock_ui/features/control_room/router.dart';
|
||||
import 'package:tatlock_ui/features/front_hall/presentation/pages/front_hall_page.dart';
|
||||
import 'package:tatlock_ui/features/security/router.dart';
|
||||
import 'package:tatlock_ui/features/settings/presentation/pages/settings_page.dart';
|
||||
import 'package:tatlock_ui/shared/layouts/app_scaffold.dart';
|
||||
|
||||
part 'app_router.g.dart';
|
||||
@@ -52,7 +53,7 @@ GoRouter appRouter(Ref ref) {
|
||||
path: AppRoutes.settings,
|
||||
name: 'settings',
|
||||
pageBuilder: (context, state) =>
|
||||
noTransitionPage(context, state, const _PlaceholderPage(title: 'Settings')),
|
||||
noTransitionPage(context, state, const SettingsPage()),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:tatlock_ui/core/auth/auth_provider.dart';
|
||||
import 'package:tatlock_ui/core/theme/theme_provider.dart';
|
||||
import 'package:tatlock_ui/routing/app_router.dart';
|
||||
|
||||
/// Profile dropdown menu in the header.
|
||||
@@ -13,6 +16,7 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final authState = ref.watch(authProvider);
|
||||
final currentTheme = ref.watch(themeProvider);
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return authState.when(
|
||||
@@ -76,6 +80,102 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
|
||||
// Theme submenu header
|
||||
PopupMenuItem<String>(
|
||||
enabled: false,
|
||||
height: 32,
|
||||
child: Text(
|
||||
'THEME',
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Theme: System
|
||||
PopupMenuItem<String>(
|
||||
value: 'theme_system',
|
||||
height: 40,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.brightness_auto,
|
||||
size: 18,
|
||||
color: currentTheme == ThemeSetting.system
|
||||
? colorScheme.primary
|
||||
: null,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'System',
|
||||
style: currentTheme == ThemeSetting.system
|
||||
? TextStyle(color: colorScheme.primary)
|
||||
: null,
|
||||
),
|
||||
const Spacer(),
|
||||
if (currentTheme == ThemeSetting.system)
|
||||
Icon(Icons.check, size: 16, color: colorScheme.primary),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Theme: Light
|
||||
PopupMenuItem<String>(
|
||||
value: 'theme_light',
|
||||
height: 40,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.light_mode,
|
||||
size: 18,
|
||||
color: currentTheme == ThemeSetting.light
|
||||
? colorScheme.primary
|
||||
: null,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'Light',
|
||||
style: currentTheme == ThemeSetting.light
|
||||
? TextStyle(color: colorScheme.primary)
|
||||
: null,
|
||||
),
|
||||
const Spacer(),
|
||||
if (currentTheme == ThemeSetting.light)
|
||||
Icon(Icons.check, size: 16, color: colorScheme.primary),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Theme: Dark
|
||||
PopupMenuItem<String>(
|
||||
value: 'theme_dark',
|
||||
height: 40,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.dark_mode,
|
||||
size: 18,
|
||||
color: currentTheme == ThemeSetting.dark
|
||||
? colorScheme.primary
|
||||
: null,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'Dark',
|
||||
style: currentTheme == ThemeSetting.dark
|
||||
? TextStyle(color: colorScheme.primary)
|
||||
: null,
|
||||
),
|
||||
const Spacer(),
|
||||
if (currentTheme == ThemeSetting.dark)
|
||||
Icon(Icons.check, size: 16, color: colorScheme.primary),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const PopupMenuDivider(),
|
||||
|
||||
// Logout (only if authenticated)
|
||||
if (auth.isAuthenticated)
|
||||
const PopupMenuItem<String>(
|
||||
@@ -93,6 +193,12 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
switch (value) {
|
||||
case 'settings':
|
||||
context.go(AppRoutes.settings);
|
||||
case 'theme_system':
|
||||
_updateTheme(ref, ThemeSetting.system);
|
||||
case 'theme_light':
|
||||
_updateTheme(ref, ThemeSetting.light);
|
||||
case 'theme_dark':
|
||||
_updateTheme(ref, ThemeSetting.dark);
|
||||
case 'logout':
|
||||
ref.read(authProvider.notifier).signOut();
|
||||
}
|
||||
@@ -126,4 +232,20 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
}
|
||||
return name[0].toUpperCase();
|
||||
}
|
||||
|
||||
/// Update theme locally and sync to API.
|
||||
Future<void> _updateTheme(WidgetRef ref, ThemeSetting setting) async {
|
||||
// Update local theme immediately for instant UI response
|
||||
await ref.read(themeProvider.notifier).setSetting(setting);
|
||||
|
||||
// Sync to backend (fire-and-forget, errors logged not shown)
|
||||
try {
|
||||
await ref.read(authProvider.notifier).updatePreferences(
|
||||
theme: setting.name,
|
||||
);
|
||||
} catch (e) {
|
||||
// Theme still works locally even if API sync fails
|
||||
developer.log('Failed to sync theme preference: $e', name: 'profile');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.1.12+1
|
||||
version: 1.1.15+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.10.4
|
||||
|
||||
+2
-1
@@ -36,7 +36,8 @@
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #1a1a2e;
|
||||
/* Match Flutter's dark theme scaffold background (FlexScheme.aquaBlue) */
|
||||
background-color: #111111;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user