mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-29 09:20:56 +01:00
65 lines
2.3 KiB
Dart
65 lines
2.3 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:material_ui/material_ui.dart';
|
|
import 'package:wger/core/app_settings_notifier.dart';
|
|
import 'package:wger/core/consts.dart';
|
|
import 'package:wger/l10n/generated/app_localizations.dart';
|
|
import 'package:wger/theme/dynamic_color.dart';
|
|
|
|
class SettingsTheme extends ConsumerWidget {
|
|
const SettingsTheme({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final i18n = AppLocalizations.of(context);
|
|
final currentMode = ref.watch(
|
|
appSettingsProvider.select((s) => s.value?.themeMode ?? ThemeMode.system),
|
|
);
|
|
final useDynamicColor = ref.watch(
|
|
appSettingsProvider.select((s) => s.value?.useDynamicColor ?? USE_DYNAMIC_COLOR_DEFAULT),
|
|
);
|
|
// Hidden while the probe is still running and where it comes back negative:
|
|
// the toggle does nothing on a platform without a dynamic palette.
|
|
final showDynamicColor = ref.watch(dynamicColorAvailableProvider).value ?? false;
|
|
|
|
return Column(
|
|
children: [
|
|
ListTile(
|
|
title: Text(i18n.themeMode),
|
|
trailing: DropdownButton<ThemeMode>(
|
|
key: const ValueKey('themeModeDropdown'),
|
|
value: currentMode,
|
|
onChanged: (ThemeMode? newValue) {
|
|
if (newValue != null) {
|
|
ref.read(appSettingsProvider.notifier).setThemeMode(newValue);
|
|
}
|
|
},
|
|
items: ThemeMode.values.map<DropdownMenuItem<ThemeMode>>((ThemeMode value) {
|
|
final label = (() {
|
|
switch (value) {
|
|
case ThemeMode.system:
|
|
return i18n.systemMode;
|
|
case ThemeMode.light:
|
|
return i18n.lightMode;
|
|
case ThemeMode.dark:
|
|
return i18n.darkMode;
|
|
}
|
|
})();
|
|
|
|
return DropdownMenuItem<ThemeMode>(value: value, child: Text(label));
|
|
}).toList(),
|
|
),
|
|
),
|
|
if (showDynamicColor)
|
|
SwitchListTile(
|
|
key: const ValueKey('useDynamicColorSwitch'),
|
|
title: Text(i18n.useDynamicColor),
|
|
value: useDynamicColor,
|
|
onChanged: (bool value) {
|
|
ref.read(appSettingsProvider.notifier).setUseDynamicColor(value);
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|