2023-08-17 18:10:24 -04:00
|
|
|
import 'package:animated_theme_switcher/animated_theme_switcher.dart';
|
|
|
|
import 'package:awesome_extensions/awesome_extensions.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
2023-01-10 21:04:18 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2023-08-17 18:10:24 -04:00
|
|
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
2023-01-10 21:04:18 -05:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2023-08-17 18:10:24 -04:00
|
|
|
import 'package:flutter_translate/flutter_translate.dart';
|
2023-01-10 21:04:18 -05:00
|
|
|
|
2023-08-17 18:10:24 -04:00
|
|
|
import '../components/default_app_bar.dart';
|
|
|
|
import '../components/signal_strength_meter.dart';
|
|
|
|
import '../entities/preferences.dart';
|
|
|
|
import '../providers/window_control.dart';
|
|
|
|
import '../tools/tools.dart';
|
|
|
|
|
|
|
|
class SettingsPage extends ConsumerStatefulWidget {
|
|
|
|
const SettingsPage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
SettingsPageState createState() => SettingsPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class SettingsPageState extends ConsumerState<SettingsPage> {
|
|
|
|
final _formKey = GlobalKey<FormBuilderState>();
|
|
|
|
late bool isInAsyncCall = false;
|
2023-08-27 11:51:42 -04:00
|
|
|
// ThemePreferences? themePreferences;
|
2023-08-17 18:10:24 -04:00
|
|
|
static const String formFieldTheme = 'theme';
|
2023-08-27 11:51:42 -04:00
|
|
|
static const String formFieldBrightness = 'brightness';
|
2023-08-17 18:10:24 -04:00
|
|
|
// static const String formFieldTitle = 'title';
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
List<DropdownMenuItem<dynamic>> _getThemeDropdownItems() {
|
|
|
|
const colorPrefs = ColorPreference.values;
|
|
|
|
final colorNames = {
|
|
|
|
ColorPreference.scarlet: translate('themes.scarlet'),
|
|
|
|
ColorPreference.vapor: translate('themes.vapor'),
|
|
|
|
ColorPreference.babydoll: translate('themes.babydoll'),
|
|
|
|
ColorPreference.gold: translate('themes.gold'),
|
|
|
|
ColorPreference.garden: translate('themes.garden'),
|
|
|
|
ColorPreference.forest: translate('themes.forest'),
|
|
|
|
ColorPreference.arctic: translate('themes.arctic'),
|
|
|
|
ColorPreference.lapis: translate('themes.lapis'),
|
|
|
|
ColorPreference.eggplant: translate('themes.eggplant'),
|
|
|
|
ColorPreference.lime: translate('themes.lime'),
|
|
|
|
ColorPreference.grim: translate('themes.grim'),
|
|
|
|
ColorPreference.contrast: translate('themes.contrast')
|
|
|
|
};
|
|
|
|
|
|
|
|
return colorPrefs
|
|
|
|
.map((e) => DropdownMenuItem(value: e, child: Text(colorNames[e]!)))
|
|
|
|
.toList();
|
|
|
|
}
|
2023-01-10 21:04:18 -05:00
|
|
|
|
2023-08-27 11:51:42 -04:00
|
|
|
List<DropdownMenuItem<dynamic>> _getBrightnessDropdownItems() {
|
|
|
|
const brightnessPrefs = BrightnessPreference.values;
|
|
|
|
final brightnessNames = {
|
|
|
|
BrightnessPreference.system: translate('brightness.system'),
|
|
|
|
BrightnessPreference.light: translate('brightness.light'),
|
|
|
|
BrightnessPreference.dark: translate('brightness.dark')
|
|
|
|
};
|
|
|
|
|
|
|
|
return brightnessPrefs
|
|
|
|
.map(
|
|
|
|
(e) => DropdownMenuItem(value: e, child: Text(brightnessNames[e]!)))
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
|
2023-01-10 21:04:18 -05:00
|
|
|
@override
|
2023-08-17 18:10:24 -04:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
ref.watch(windowControlProvider);
|
2023-08-27 11:51:42 -04:00
|
|
|
final themeService = ref.watch(themeServiceProvider).valueOrNull;
|
|
|
|
if (themeService == null) {
|
|
|
|
return waitingPage(context);
|
|
|
|
}
|
|
|
|
final themePreferences = themeService.load();
|
2023-08-17 18:10:24 -04:00
|
|
|
|
|
|
|
return ThemeSwitchingArea(
|
|
|
|
child: Scaffold(
|
|
|
|
// resizeToAvoidBottomInset: false,
|
|
|
|
appBar: DefaultAppBar(
|
|
|
|
title: Text(translate('settings_page.titlebar')),
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
onPressed: () => context.pop<void>(),
|
|
|
|
),
|
2023-08-27 11:51:42 -04:00
|
|
|
actions: <Widget>[
|
|
|
|
const SignalStrengthMeterWidget().paddingLTRB(16, 0, 16, 0),
|
2023-08-17 18:10:24 -04:00
|
|
|
]),
|
|
|
|
|
|
|
|
body: FormBuilder(
|
|
|
|
key: _formKey,
|
|
|
|
child: ListView(
|
2023-01-10 21:04:18 -05:00
|
|
|
children: [
|
2023-08-17 18:10:24 -04:00
|
|
|
ThemeSwitcher.withTheme(
|
|
|
|
builder: (_, switcher, theme) => FormBuilderDropdown(
|
|
|
|
name: formFieldTheme,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
label: Text(translate('settings_page.color_theme'))),
|
|
|
|
items: _getThemeDropdownItems(),
|
2023-08-27 11:51:42 -04:00
|
|
|
initialValue: themePreferences.colorPreference,
|
2023-08-17 18:10:24 -04:00
|
|
|
onChanged: (value) async {
|
2023-08-27 11:51:42 -04:00
|
|
|
final newPrefs = themePreferences.copyWith(
|
|
|
|
colorPreference: value as ColorPreference);
|
|
|
|
await themeService.save(newPrefs);
|
|
|
|
switcher.changeTheme(theme: themeService.get(newPrefs));
|
|
|
|
ref.invalidate(themeServiceProvider);
|
|
|
|
setState(() {});
|
|
|
|
})),
|
|
|
|
ThemeSwitcher.withTheme(
|
|
|
|
builder: (_, switcher, theme) => FormBuilderDropdown(
|
|
|
|
name: formFieldBrightness,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
label:
|
|
|
|
Text(translate('settings_page.brightness_mode'))),
|
|
|
|
items: _getBrightnessDropdownItems(),
|
|
|
|
initialValue: themePreferences.brightnessPreference,
|
|
|
|
onChanged: (value) async {
|
|
|
|
final newPrefs = themePreferences.copyWith(
|
|
|
|
brightnessPreference: value as BrightnessPreference);
|
|
|
|
await themeService.save(newPrefs);
|
|
|
|
switcher.changeTheme(theme: themeService.get(newPrefs));
|
|
|
|
ref.invalidate(themeServiceProvider);
|
|
|
|
setState(() {});
|
|
|
|
})),
|
2023-01-10 21:04:18 -05:00
|
|
|
],
|
|
|
|
),
|
2023-08-17 18:10:24 -04:00
|
|
|
).paddingSymmetric(horizontal: 24, vertical: 8),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
|
|
|
super.debugFillProperties(properties);
|
|
|
|
properties.add(DiagnosticsProperty<bool>('isInAsyncCall', isInAsyncCall));
|
|
|
|
}
|
2023-01-10 21:04:18 -05:00
|
|
|
}
|