This commit is contained in:
Christien Rioux 2023-08-27 11:51:42 -04:00
parent 411705283d
commit e369d6091a
8 changed files with 95 additions and 98 deletions

View File

@ -118,8 +118,14 @@
"grim": "Grim", "grim": "Grim",
"contrast": "Contrast" "contrast": "Contrast"
}, },
"brightness": {
"system": "System",
"light": "Light",
"dark": "Dark"
},
"settings_page": { "settings_page": {
"titlebar": "Settings", "titlebar": "Settings",
"color_theme": "Color Theme" "color_theme": "Color Theme",
"brightness_mode": "Brightness Mode"
} }
} }

View File

@ -27,24 +27,23 @@ class SettingsPage extends ConsumerStatefulWidget {
class SettingsPageState extends ConsumerState<SettingsPage> { class SettingsPageState extends ConsumerState<SettingsPage> {
final _formKey = GlobalKey<FormBuilderState>(); final _formKey = GlobalKey<FormBuilderState>();
late bool isInAsyncCall = false; late bool isInAsyncCall = false;
ThemeService? themeService; // ThemePreferences? themePreferences;
ThemePreferences? themePreferences;
static const String formFieldTheme = 'theme'; static const String formFieldTheme = 'theme';
static const String formFieldBrightness = 'brightness';
// static const String formFieldTitle = 'title'; // static const String formFieldTitle = 'title';
@override @override
void initState() { void initState() {
super.initState(); super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async { // WidgetsBinding.instance.addPostFrameCallback((_) async {
await ref.read(windowControlProvider.notifier).changeWindowSetup( // await ref.read(windowControlProvider.notifier).changeWindowSetup(
TitleBarStyle.normal, OrientationCapability.normal); // TitleBarStyle.normal, OrientationCapability.normal);
final tsinst = await ThemeService.instance; // final tsinst = await ThemeService.instance;
setState(() { // setState(() {
themeService = tsinst; // themePreferences = tsinst.load();
themePreferences = tsinst.load(); // });
}); // });
});
} }
List<DropdownMenuItem<dynamic>> _getThemeDropdownItems() { List<DropdownMenuItem<dynamic>> _getThemeDropdownItems() {
@ -69,10 +68,28 @@ class SettingsPageState extends ConsumerState<SettingsPage> {
.toList(); .toList();
} }
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();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
ref.watch(windowControlProvider); ref.watch(windowControlProvider);
final themeService = ref.watch(themeServiceProvider).asData(); final themeService = ref.watch(themeServiceProvider).valueOrNull;
if (themeService == null) {
return waitingPage(context);
}
final themePreferences = themeService.load();
return ThemeSwitchingArea( return ThemeSwitchingArea(
child: Scaffold( child: Scaffold(
@ -83,8 +100,8 @@ class SettingsPageState extends ConsumerState<SettingsPage> {
icon: const Icon(Icons.arrow_back), icon: const Icon(Icons.arrow_back),
onPressed: () => context.pop<void>(), onPressed: () => context.pop<void>(),
), ),
actions: const <Widget>[ actions: <Widget>[
SignalStrengthMeterWidget(), const SignalStrengthMeterWidget().paddingLTRB(16, 0, 16, 0),
]), ]),
body: FormBuilder( body: FormBuilder(
@ -97,69 +114,31 @@ class SettingsPageState extends ConsumerState<SettingsPage> {
decoration: InputDecoration( decoration: InputDecoration(
label: Text(translate('settings_page.color_theme'))), label: Text(translate('settings_page.color_theme'))),
items: _getThemeDropdownItems(), items: _getThemeDropdownItems(),
initialValue: themePreferences?.colorPreference, initialValue: themePreferences.colorPreference,
onChanged: (value) async { onChanged: (value) async {
final tprefs = themePreferences; final newPrefs = themePreferences.copyWith(
if (tprefs != null) { colorPreference: value as ColorPreference);
final newPrefs = tprefs.copyWith( await themeService.save(newPrefs);
colorPreference: value as ColorPreference); switcher.changeTheme(theme: themeService.get(newPrefs));
final tservice = themeService; ref.invalidate(themeServiceProvider);
if (tservice != null) { setState(() {});
await tservice.save(newPrefs); })),
switcher.changeTheme(theme: tservice.get(newPrefs)); ThemeSwitcher.withTheme(
} builder: (_, switcher, theme) => FormBuilderDropdown(
setState(() { name: formFieldBrightness,
themePreferences = newPrefs; decoration: InputDecoration(
}); label:
} Text(translate('settings_page.brightness_mode'))),
})) items: _getBrightnessDropdownItems(),
initialValue: themePreferences.brightnessPreference,
// Text(translate('settings_page.header')) onChanged: (value) async {
// .textStyle(context.headlineSmall) final newPrefs = themePreferences.copyWith(
// .paddingSymmetric(vertical: 16), brightnessPreference: value as BrightnessPreference);
// FormBuilderTextField( await themeService.save(newPrefs);
// autofocus: true, switcher.changeTheme(theme: themeService.get(newPrefs));
// name: formFieldName, ref.invalidate(themeServiceProvider);
// decoration: setState(() {});
// InputDecoration(hintText: translate('account.form_name')), })),
// maxLength: 64,
// // The validator receives the text that the user has entered.
// validator: FormBuilderValidators.compose([
// FormBuilderValidators.required(),
// ]),
// ),
// FormBuilderTextField(
// name: formFieldTitle,
// maxLength: 64,
// decoration:
// InputDecoration(hintText: translate('account.form_title')),
// ),
// Row(children: [
// const Spacer(),
// Text(translate('new_account_page.instructions'))
// .toCenter()
// .flexible(flex: 6),
// const Spacer(),
// ]).paddingSymmetric(vertical: 4),
// ElevatedButton(
// onPressed: () async {
// if (_formKey.currentState?.saveAndValidate() ?? false) {
// setState(() {
// isInAsyncCall = true;
// });
// try {
// await onSubmit(_formKey);
// } finally {
// if (mounted) {
// setState(() {
// isInAsyncCall = false;
// });
// }
// }
// }
// },
// child: Text(translate('new_account_page.create')),
// ).paddingSymmetric(vertical: 4).alignAtCenterRight(),
], ],
), ),
).paddingSymmetric(horizontal: 24, vertical: 8), ).paddingSymmetric(horizontal: 24, vertical: 8),

View File

@ -203,7 +203,8 @@ class ThemeService {
ThemePreferences? themePreferences; ThemePreferences? themePreferences;
if (themePreferencesJson != null) { if (themePreferencesJson != null) {
try { try {
themePreferences = ThemePreferences.fromJson(themePreferencesJson); themePreferences =
ThemePreferences.fromJson(jsonDecode(themePreferencesJson));
// ignore: avoid_catches_without_on_clauses // ignore: avoid_catches_without_on_clauses
} catch (_) { } catch (_) {
// ignore // ignore
@ -273,4 +274,5 @@ class ThemeService {
} }
@riverpod @riverpod
Future<ThemeService> themeService() => ThemeService.instance; FutureOr<ThemeService> themeService(ThemeServiceRef ref) async =>
await ThemeService.instance;

View File

@ -6,7 +6,7 @@ part of 'theme_service.dart';
// RiverpodGenerator // RiverpodGenerator
// ************************************************************************** // **************************************************************************
String _$themeServiceHash() => r'a319ae893d3b5cf5718a0c1a21c22bd073f5fd34'; String _$themeServiceHash() => r'87dbacb9df4923f507fb01e486b91d73a3fcef9c';
/// See also [themeService]. /// See also [themeService].
@ProviderFor(themeService) @ProviderFor(themeService)

View File

@ -23,9 +23,11 @@ Future<VeilidConfig> getVeilidChatConfig() async {
config = config.copyWith( config = config.copyWith(
network: config.network.copyWith( network: config.network.copyWith(
dht: config.network.dht.copyWith( dht: config.network.dht.copyWith(
getValueCount: 2, //getValueCount: 2,
getValueFanout: 8,
getValueTimeoutMs: 5000, getValueTimeoutMs: 5000,
setValueCount: 2, //setValueCount: 2,
setValueFanout: 10,
setValueTimeoutMs: 5000))); setValueTimeoutMs: 5000)));
return config; return config;

View File

@ -208,7 +208,7 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 0920; LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300; LastUpgradeCheck = 1430;
ORGANIZATIONNAME = ""; ORGANIZATIONNAME = "";
TargetAttributes = { TargetAttributes = {
33CC10EC2044A3C60003C045 = { 33CC10EC2044A3C60003C045 = {

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "1300" LastUpgradeVersion = "1430"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"

View File

@ -277,10 +277,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.17.1" version: "1.17.2"
convert: convert:
dependency: transitive dependency: transitive
description: description:
@ -673,10 +673,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: intl name: intl
sha256: a3715e3bc90294e971cb7dc063fbf3cd9ee0ebf8604ffeafabd9e6f16abbdbe6 sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.18.0" version: "0.18.1"
io: io:
dependency: transitive dependency: transitive
description: description:
@ -745,18 +745,18 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.12.15" version: "0.12.16"
material_color_utilities: material_color_utilities:
dependency: transitive dependency: transitive
description: description:
name: material_color_utilities name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.2.0" version: "0.5.0"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@ -1182,10 +1182,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: source_span name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.9.1" version: "1.10.0"
split_view: split_view:
dependency: "direct main" dependency: "direct main"
description: description:
@ -1294,10 +1294,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.5.1" version: "0.6.0"
timing: timing:
dependency: transitive dependency: transitive
description: description:
@ -1440,7 +1440,7 @@ packages:
path: "../veilid/veilid-flutter" path: "../veilid/veilid-flutter"
relative: true relative: true
source: path source: path
version: "0.1.7" version: "0.1.10"
visibility_detector: visibility_detector:
dependency: transitive dependency: transitive
description: description:
@ -1457,6 +1457,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.1.0" version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
web_socket_channel: web_socket_channel:
dependency: transitive dependency: transitive
description: description:
@ -1506,5 +1514,5 @@ packages:
source: hosted source: hosted
version: "3.1.2" version: "3.1.2"
sdks: sdks:
dart: ">=3.0.5 <4.0.0" dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.10.6" flutter: ">=3.10.6"