2022-08-16 01:53:30 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2022-08-16 01:53:30 +02:00
|
|
|
import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
|
|
|
|
import 'package:immich_mobile/utils/immich_app_theme.dart';
|
|
|
|
|
|
|
|
class ThemeSetting extends HookConsumerWidget {
|
|
|
|
const ThemeSetting({
|
2024-01-27 18:14:32 +02:00
|
|
|
super.key,
|
|
|
|
});
|
2022-08-16 01:53:30 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final currentTheme = useState<ThemeMode>(ThemeMode.system);
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
currentTheme.value = ref.read(immichThemeProvider);
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
|
|
|
|
return ExpansionTile(
|
2023-11-09 18:19:53 +02:00
|
|
|
textColor: context.primaryColor,
|
2023-11-20 16:58:03 +02:00
|
|
|
title: Text(
|
2022-08-16 01:53:30 +02:00
|
|
|
'theme_setting_theme_title',
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.titleMedium,
|
2022-08-16 01:53:30 +02:00
|
|
|
).tr(),
|
|
|
|
subtitle: const Text(
|
|
|
|
'theme_setting_theme_subtitle',
|
|
|
|
).tr(),
|
|
|
|
children: [
|
|
|
|
SwitchListTile.adaptive(
|
2023-11-09 18:19:53 +02:00
|
|
|
activeColor: context.primaryColor,
|
2023-06-29 05:33:57 +02:00
|
|
|
title: Text(
|
2022-08-16 01:53:30 +02:00
|
|
|
'theme_setting_system_theme_switch',
|
2023-11-09 18:19:53 +02:00
|
|
|
style: context.textTheme.labelLarge
|
2023-06-29 05:33:57 +02:00
|
|
|
?.copyWith(fontWeight: FontWeight.bold),
|
2022-08-16 01:53:30 +02:00
|
|
|
).tr(),
|
|
|
|
value: currentTheme.value == ThemeMode.system,
|
|
|
|
onChanged: (bool isSystem) {
|
|
|
|
var currentSystemBrightness =
|
|
|
|
MediaQuery.of(context).platformBrightness;
|
|
|
|
|
|
|
|
if (isSystem) {
|
|
|
|
currentTheme.value = ThemeMode.system;
|
|
|
|
ref.watch(immichThemeProvider.notifier).state = ThemeMode.system;
|
|
|
|
ref
|
|
|
|
.watch(appSettingsServiceProvider)
|
|
|
|
.setSetting(AppSettingsEnum.themeMode, "system");
|
|
|
|
} else {
|
|
|
|
if (currentSystemBrightness == Brightness.light) {
|
|
|
|
currentTheme.value = ThemeMode.light;
|
|
|
|
ref.watch(immichThemeProvider.notifier).state = ThemeMode.light;
|
|
|
|
ref
|
|
|
|
.watch(appSettingsServiceProvider)
|
|
|
|
.setSetting(AppSettingsEnum.themeMode, "light");
|
|
|
|
} else if (currentSystemBrightness == Brightness.dark) {
|
|
|
|
currentTheme.value = ThemeMode.dark;
|
|
|
|
ref.watch(immichThemeProvider.notifier).state = ThemeMode.dark;
|
|
|
|
ref
|
|
|
|
.watch(appSettingsServiceProvider)
|
|
|
|
.setSetting(AppSettingsEnum.themeMode, "dark");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (currentTheme.value != ThemeMode.system)
|
|
|
|
SwitchListTile.adaptive(
|
2023-11-09 18:19:53 +02:00
|
|
|
activeColor: context.primaryColor,
|
2023-06-29 05:33:57 +02:00
|
|
|
title: Text(
|
2022-08-16 01:53:30 +02:00
|
|
|
'theme_setting_dark_mode_switch',
|
2023-11-09 18:19:53 +02:00
|
|
|
style: context.textTheme.labelLarge
|
2023-06-29 05:33:57 +02:00
|
|
|
?.copyWith(fontWeight: FontWeight.bold),
|
2022-08-16 01:53:30 +02:00
|
|
|
).tr(),
|
|
|
|
value: ref.watch(immichThemeProvider) == ThemeMode.dark,
|
|
|
|
onChanged: (bool isDark) {
|
|
|
|
if (isDark) {
|
|
|
|
ref.watch(immichThemeProvider.notifier).state = ThemeMode.dark;
|
|
|
|
ref
|
|
|
|
.watch(appSettingsServiceProvider)
|
|
|
|
.setSetting(AppSettingsEnum.themeMode, "dark");
|
|
|
|
} else {
|
|
|
|
ref.watch(immichThemeProvider.notifier).state = ThemeMode.light;
|
|
|
|
ref
|
|
|
|
.watch(appSettingsServiceProvider)
|
|
|
|
.setSetting(AppSettingsEnum.themeMode, "light");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|