MHosssam
Committed by GitHub

Update simple_builder.dart

... ... @@ -5,7 +5,7 @@ import 'list_notifier.dart';
typedef ValueBuilderUpdateCallback<T> = void Function(T snapshot);
typedef ValueBuilderBuilder<T> = Widget Function(
T? snapshot, ValueBuilderUpdateCallback<T> updater);
T snapshot, ValueBuilderUpdateCallback<T> updater);
/// Manages a local state like ObxValue, but uses a callback instead of
/// a Rx value.
... ... @@ -23,36 +23,32 @@ typedef ValueBuilderBuilder<T> = Widget Function(
/// ),
/// ```
class ValueBuilder<T> extends StatefulWidget {
final T? initialValue;
final T initialValue;
final ValueBuilderBuilder<T> builder;
final void Function()? onDispose;
final void Function(T)? onUpdate;
const ValueBuilder({
Key? key,
this.initialValue,
required this.initialValue,
this.onDispose,
this.onUpdate,
required this.builder,
}) : super(key: key);
@override
_ValueBuilderState<T> createState() => _ValueBuilderState<T>();
_ValueBuilderState<T> createState() => _ValueBuilderState<T>(initialValue);
}
class _ValueBuilderState<T> extends State<ValueBuilder<T?>> {
T? value;
T value;
_ValueBuilderState(this.value);
@override
void initState() {
super.initState();
value = widget.initialValue;
}
@override
Widget build(BuildContext context) => widget.builder(value, updater);
void updater(T? newValue) {
void updater(T newValue) {
if (widget.onUpdate != null) {
widget.onUpdate!(newValue);
}
... ... @@ -70,7 +66,6 @@ class _ValueBuilderState<T> extends State<ValueBuilder<T?>> {
} else if (value is StreamController) {
(value as StreamController?)?.close();
}
value = null;
}
}
... ...