From 91faa0ab7c8cd243cb409f56cbeb764929fd0ca6 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Wed, 19 Jul 2023 12:24:55 +0200 Subject: [PATCH 1/2] style(neon): export LabelBuilder from sort_box and settings --- packages/neon/neon/lib/settings.dart | 1 + packages/neon/neon/lib/sort_box.dart | 1 + .../lib/src/{settings/widgets => models}/label_builder.dart | 2 -- packages/neon/neon/lib/src/settings/models/option.dart | 2 +- .../neon/neon/lib/src/settings/models/options_category.dart | 2 +- packages/neon/neon/lib/src/settings/models/select_option.dart | 2 +- .../neon/lib/src/sort_box/sort_box_order_option_values.dart | 2 +- 7 files changed, 6 insertions(+), 6 deletions(-) rename packages/neon/neon/lib/src/{settings/widgets => models}/label_builder.dart (68%) diff --git a/packages/neon/neon/lib/settings.dart b/packages/neon/neon/lib/settings.dart index e8d9b756..15823bf3 100644 --- a/packages/neon/neon/lib/settings.dart +++ b/packages/neon/neon/lib/settings.dart @@ -1,3 +1,4 @@ +export 'package:neon/src/models/label_builder.dart'; export 'package:neon/src/settings/models/nextcloud_app_options.dart'; export 'package:neon/src/settings/models/options_category.dart'; export 'package:neon/src/settings/models/select_option.dart'; diff --git a/packages/neon/neon/lib/sort_box.dart b/packages/neon/neon/lib/sort_box.dart index e66072f2..65ffbafd 100644 --- a/packages/neon/neon/lib/sort_box.dart +++ b/packages/neon/neon/lib/sort_box.dart @@ -1,3 +1,4 @@ +export 'package:neon/src/models/label_builder.dart'; export 'package:neon/src/sort_box/sort_box_builder.dart'; export 'package:neon/src/sort_box/sort_box_order_option_values.dart'; export 'package:sort_box/sort_box.dart'; diff --git a/packages/neon/neon/lib/src/settings/widgets/label_builder.dart b/packages/neon/neon/lib/src/models/label_builder.dart similarity index 68% rename from packages/neon/neon/lib/src/settings/widgets/label_builder.dart rename to packages/neon/neon/lib/src/models/label_builder.dart index 76f20caf..82baa178 100644 --- a/packages/neon/neon/lib/src/settings/widgets/label_builder.dart +++ b/packages/neon/neon/lib/src/models/label_builder.dart @@ -1,5 +1,3 @@ import 'package:flutter/widgets.dart'; -import 'package:meta/meta.dart'; -@internal typedef LabelBuilder = String Function(BuildContext); diff --git a/packages/neon/neon/lib/src/settings/models/option.dart b/packages/neon/neon/lib/src/settings/models/option.dart index 0668d38e..5e9d57e9 100644 --- a/packages/neon/neon/lib/src/settings/models/option.dart +++ b/packages/neon/neon/lib/src/settings/models/option.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:meta/meta.dart'; +import 'package:neon/src/models/label_builder.dart'; import 'package:neon/src/settings/models/options_category.dart'; import 'package:neon/src/settings/models/storage.dart'; -import 'package:neon/src/settings/widgets/label_builder.dart'; import 'package:rxdart/rxdart.dart'; @internal diff --git a/packages/neon/neon/lib/src/settings/models/options_category.dart b/packages/neon/neon/lib/src/settings/models/options_category.dart index d057552f..d563c210 100644 --- a/packages/neon/neon/lib/src/settings/models/options_category.dart +++ b/packages/neon/neon/lib/src/settings/models/options_category.dart @@ -1,4 +1,4 @@ -import 'package:neon/src/settings/widgets/label_builder.dart'; +import 'package:neon/src/models/label_builder.dart'; class OptionsCategory { OptionsCategory({ diff --git a/packages/neon/neon/lib/src/settings/models/select_option.dart b/packages/neon/neon/lib/src/settings/models/select_option.dart index 1d3bd47f..5d3fc7da 100644 --- a/packages/neon/neon/lib/src/settings/models/select_option.dart +++ b/packages/neon/neon/lib/src/settings/models/select_option.dart @@ -1,8 +1,8 @@ import 'dart:async'; import 'package:collection/collection.dart'; +import 'package:neon/src/models/label_builder.dart'; import 'package:neon/src/settings/models/option.dart'; -import 'package:neon/src/settings/widgets/label_builder.dart'; class SelectOption extends Option { /// Creates a SelectOption diff --git a/packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart b/packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart index f6f4d5c5..2d69f581 100644 --- a/packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart +++ b/packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart @@ -1,5 +1,5 @@ import 'package:neon/l10n/localizations.dart'; -import 'package:neon/src/settings/widgets/label_builder.dart'; +import 'package:neon/src/models/label_builder.dart'; import 'package:sort_box/sort_box.dart'; final sortBoxOrderOptionValues = { From 52c32f422a132f3d3abc6107de0b2910aebae145 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Wed, 19 Jul 2023 12:24:58 +0200 Subject: [PATCH 2/2] fix(neon): fix late initialization of SelectOption.values --- .../src/settings/models/select_option.dart | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/neon/neon/lib/src/settings/models/select_option.dart b/packages/neon/neon/lib/src/settings/models/select_option.dart index 5d3fc7da..e1d7e110 100644 --- a/packages/neon/neon/lib/src/settings/models/select_option.dart +++ b/packages/neon/neon/lib/src/settings/models/select_option.dart @@ -12,10 +12,16 @@ class SelectOption extends Option { required super.label, required super.defaultValue, required final Map values, + + /// Force loading the stored value. + /// + /// This is needed when [values] is empty but the stored value should still be loaded. + /// This only works when [T] is of type String?. + final bool forceLoadValue = true, super.category, super.enabled, }) : _values = values, - super(initialValue: _fromString(values, storage.getString(key))); + super(initialValue: loadValue(values, storage.getString(key), forceLoad: forceLoadValue)); /// Creates a SelectOption depending on the State of another [Option]. SelectOption.depend({ @@ -25,9 +31,23 @@ class SelectOption extends Option { required super.defaultValue, required final Map values, required super.enabled, + + /// Force loading the stored value. + /// + /// This is needed when [values] is empty but the stored value should still be loaded. + /// This only works when [T] is of type String?. + final bool forceLoadValue = true, super.category, }) : _values = values, - super.depend(initialValue: _fromString(values, storage.getString(key))); + super.depend(initialValue: loadValue(values, storage.getString(key), forceLoad: forceLoadValue)); + + static T? loadValue(final Map vs, final String? stored, {final bool forceLoad = true}) { + if (forceLoad && vs.isEmpty && stored is T) { + return stored as T; + } + + return _fromString(vs, stored); + } static T? _fromString(final Map vs, final String? valueStr) { if (valueStr == null) {