2026-07-30 12:39:24 -07:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
2024-03-12 14:56:08 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-11-21 22:35:58 +07:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2026-01-19 14:56:35 -06:00
|
|
|
import 'package:immich_mobile/extensions/translate_extensions.dart';
|
2026-05-30 20:57:55 +05:30
|
|
|
import 'package:immich_mobile/providers/infrastructure/settings.provider.dart';
|
2024-08-06 19:50:27 +05:30
|
|
|
import 'package:immich_mobile/widgets/settings/preference_settings/primary_color_setting.dart';
|
2026-01-19 14:56:35 -06:00
|
|
|
import 'package:immich_mobile/widgets/settings/setting_group_title.dart';
|
2024-05-06 23:04:21 -05:00
|
|
|
import 'package:immich_mobile/widgets/settings/settings_switch_list_tile.dart';
|
2024-03-12 14:56:08 +00:00
|
|
|
|
|
|
|
|
class ThemeSetting extends HookConsumerWidget {
|
2025-07-29 00:34:03 +05:30
|
|
|
const ThemeSetting({super.key});
|
2024-03-12 14:56:08 +00:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2026-08-05 01:26:49 +05:30
|
|
|
final currentTheme = useState(ref.watch(appConfigProvider.select((config) => config.theme.mode)));
|
2024-03-12 14:56:08 +00:00
|
|
|
final isDarkTheme = useValueNotifier(currentTheme.value == ThemeMode.dark);
|
2025-07-25 08:07:22 +05:30
|
|
|
final isSystemTheme = useValueNotifier(currentTheme.value == ThemeMode.system);
|
2026-05-07 22:12:14 +07:00
|
|
|
final colorfulInterface = useValueNotifier(
|
|
|
|
|
ref.watch(appConfigProvider.select((config) => config.theme.colorfulInterface)),
|
2024-08-06 19:50:27 +05:30
|
|
|
);
|
|
|
|
|
|
2024-03-12 14:56:08 +00:00
|
|
|
void onThemeChange(bool isDark) {
|
2026-05-07 22:12:14 +07:00
|
|
|
currentTheme.value = isDark ? ThemeMode.dark : ThemeMode.light;
|
2026-07-30 12:39:24 -07:00
|
|
|
unawaited(ref.read(settingsProvider).write(.themeMode, currentTheme.value));
|
2024-03-12 14:56:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onSystemThemeChange(bool isSystem) {
|
|
|
|
|
if (isSystem) {
|
2026-05-05 10:45:51 +07:00
|
|
|
currentTheme.value = ThemeMode.system;
|
2024-03-12 14:56:08 +00:00
|
|
|
isSystemTheme.value = true;
|
|
|
|
|
} else {
|
2024-11-21 22:35:58 +07:00
|
|
|
final currentSystemBrightness = context.platformBrightness;
|
2024-03-12 14:56:08 +00:00
|
|
|
isSystemTheme.value = false;
|
|
|
|
|
isDarkTheme.value = currentSystemBrightness == Brightness.dark;
|
|
|
|
|
if (currentSystemBrightness == Brightness.light) {
|
2026-05-05 10:45:51 +07:00
|
|
|
currentTheme.value = ThemeMode.light;
|
2024-03-12 14:56:08 +00:00
|
|
|
} else if (currentSystemBrightness == Brightness.dark) {
|
2026-05-05 10:45:51 +07:00
|
|
|
currentTheme.value = ThemeMode.dark;
|
2024-03-12 14:56:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-07-30 12:39:24 -07:00
|
|
|
unawaited(ref.read(settingsProvider).write(.themeMode, currentTheme.value));
|
2024-03-12 14:56:08 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-06 19:50:27 +05:30
|
|
|
void onSurfaceColorSettingChange(bool useColorfulInterface) {
|
2026-07-30 12:39:24 -07:00
|
|
|
unawaited(ref.read(settingsProvider).write(.themeColorfulInterface, useColorfulInterface));
|
2026-05-07 22:12:14 +07:00
|
|
|
colorfulInterface.value = useColorfulInterface;
|
2024-08-06 19:50:27 +05:30
|
|
|
}
|
|
|
|
|
|
2024-03-12 14:56:08 +00:00
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
2026-01-19 14:56:35 -06:00
|
|
|
SettingGroupTitle(
|
|
|
|
|
title: "theme".t(context: context),
|
|
|
|
|
icon: Icons.color_lens_outlined,
|
|
|
|
|
),
|
2024-03-12 14:56:08 +00:00
|
|
|
SettingsSwitchListTile(
|
|
|
|
|
valueNotifier: isSystemTheme,
|
2026-01-19 14:56:35 -06:00
|
|
|
title: 'theme_setting_system_theme_switch'.t(context: context),
|
2024-03-12 14:56:08 +00:00
|
|
|
onChanged: onSystemThemeChange,
|
|
|
|
|
),
|
|
|
|
|
if (currentTheme.value != ThemeMode.system)
|
|
|
|
|
SettingsSwitchListTile(
|
|
|
|
|
valueNotifier: isDarkTheme,
|
2026-01-19 14:56:35 -06:00
|
|
|
title: 'map_settings_dark_mode'.t(context: context),
|
2024-03-12 14:56:08 +00:00
|
|
|
onChanged: onThemeChange,
|
|
|
|
|
),
|
2024-08-06 19:50:27 +05:30
|
|
|
const PrimaryColorSetting(),
|
|
|
|
|
SettingsSwitchListTile(
|
2026-05-07 22:12:14 +07:00
|
|
|
valueNotifier: colorfulInterface,
|
2026-01-19 14:56:35 -06:00
|
|
|
title: "theme_setting_colorful_interface_title".t(context: context),
|
|
|
|
|
subtitle: 'theme_setting_colorful_interface_subtitle'.t(context: context),
|
2024-08-06 19:50:27 +05:30
|
|
|
onChanged: onSurfaceColorSettingChange,
|
|
|
|
|
),
|
2024-03-12 14:56:08 +00:00
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|