Browse Source

Merge pull request #504 from provokateurin/fix/option_persistence

Fix/option persistence
pull/523/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
6205e9dd55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/neon/neon/lib/settings.dart
  2. 1
      packages/neon/neon/lib/sort_box.dart
  3. 2
      packages/neon/neon/lib/src/models/label_builder.dart
  4. 2
      packages/neon/neon/lib/src/settings/models/option.dart
  5. 2
      packages/neon/neon/lib/src/settings/models/options_category.dart
  6. 26
      packages/neon/neon/lib/src/settings/models/select_option.dart
  7. 2
      packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart

1
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';

1
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';

2
packages/neon/neon/lib/src/settings/widgets/label_builder.dart → 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);

2
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

2
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({

26
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<T> extends Option<T> {
/// Creates a SelectOption
@ -12,10 +12,16 @@ class SelectOption<T> extends Option<T> {
required super.label,
required super.defaultValue,
required final Map<T, LabelBuilder> 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<T> extends Option<T> {
required super.defaultValue,
required final Map<T, LabelBuilder> 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<T>(final Map<T, LabelBuilder> 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<T>(final Map<T, LabelBuilder> vs, final String? valueStr) {
if (valueStr == null) {

2
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 = <SortBoxOrder, LabelBuilder>{

Loading…
Cancel
Save