Browse Source

neon, settings: improve nullability of OptionBuilder

pull/428/head
Nikolas Rimikis 2 years ago
parent
commit
47e0d0de1f
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 8
      packages/neon/neon/lib/src/app.dart
  2. 10
      packages/neon/neon/lib/src/utils/sort_box_builder.dart
  3. 30
      packages/settings/lib/src/widgets/checkbox_settings_tile.dart
  4. 25
      packages/settings/lib/src/widgets/option_builder.dart

8
packages/neon/neon/lib/src/app.dart

@ -254,10 +254,6 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
builder: (final context, final themeKeepOriginalAccentColor) => StreamBuilder<Account?>(
stream: _accountsBloc.activeAccount,
builder: (final context, final activeAccountSnapshot) {
if (themeMode == null || themeOLEDAsDark == null) {
return Container();
}
FlutterNativeSplash.remove();
return ResultBuilder<Capabilities?>.behaviorSubject(
stream: activeAccountSnapshot.hasData
@ -280,12 +276,12 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
theme: getThemeFromNextcloudTheme(
nextcloudTheme,
Brightness.light,
keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
keepOriginalAccentColor: nextcloudTheme == null || themeKeepOriginalAccentColor,
),
darkTheme: getThemeFromNextcloudTheme(
nextcloudTheme,
Brightness.dark,
keepOriginalAccentColor: nextcloudTheme == null || (themeKeepOriginalAccentColor ?? false),
keepOriginalAccentColor: nextcloudTheme == null || themeKeepOriginalAccentColor,
oledAsDark: themeOLEDAsDark,
),
routerConfig: _routerDelegate,

10
packages/neon/neon/lib/src/utils/sort_box_builder.dart

@ -21,12 +21,10 @@ class SortBoxBuilder<T extends Enum, R> extends StatelessWidget {
option: sortPropertyOption,
builder: (final context, final property) => OptionBuilder<SortBoxOrder>(
option: sortBoxOrderOption,
builder: (final context, final order) => property == null || order == null
? Container()
: builder(
context,
input == null ? null : sortBox.sort(input!, Box(property, order)),
),
builder: (final context, final order) => builder(
context,
input == null ? null : sortBox.sort(input!, Box(property, order)),
),
),
);
}

30
packages/settings/lib/src/widgets/checkbox_settings_tile.dart

@ -9,21 +9,19 @@ class CheckBoxSettingsTile extends InputSettingsTile<ToggleOption> {
@override
Widget build(final BuildContext context) => OptionBuilder<bool>(
option: option,
builder: (final context, final value) => value == null
? Container()
: StreamBuilder<bool>(
stream: option.enabled,
builder: (final context, final enabledSnapshot) => !enabledSnapshot.hasData
? Container()
: CheckboxListTile(
title: Text(option.label(context)),
value: value,
onChanged: enabledSnapshot.requireData
? (final value) async {
await option.set(value!);
}
: null,
),
),
builder: (final context, final value) => StreamBuilder<bool>(
stream: option.enabled,
builder: (final context, final enabledSnapshot) => !enabledSnapshot.hasData
? Container()
: CheckboxListTile(
title: Text(option.label(context)),
value: value,
onChanged: enabledSnapshot.requireData
? (final value) async {
await option.set(value!);
}
: null,
),
),
);
}

25
packages/settings/lib/src/widgets/option_builder.dart

@ -1,22 +1,23 @@
part of '../../settings.dart';
class OptionBuilder<T> extends StatelessWidget {
const OptionBuilder({
typedef OptionBuilderFunction<T> = Widget Function(BuildContext context, T snapshot);
class OptionBuilder<T> extends StreamBuilderBase<T, T> {
OptionBuilder({
required this.option,
required this.builder,
super.key,
});
}) : super(stream: option.stream);
final Option<T> option;
final Widget Function(BuildContext context, T? data) builder;
final OptionBuilderFunction<T> builder;
@override
T afterData(final T current, final T data) => data;
@override
T initial() => option.defaultValue;
@override
Widget build(final BuildContext context) => StreamBuilder<T?>(
stream: option.stream,
initialData: option.defaultValue,
builder: (final context, final valueSnapshot) => builder(
context,
valueSnapshot.data,
),
);
Widget build(final BuildContext context, final T currentSummary) => builder(context, currentSummary);
}

Loading…
Cancel
Save