Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Last active October 14, 2019 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukepighetti/f988bcc8a1593e257767226aa161744f to your computer and use it in GitHub Desktop.
Save lukepighetti/f988bcc8a1593e257767226aa161744f to your computer and use it in GitHub Desktop.
Value observable builder
import 'package:rxdart/rxdart.dart';
import 'package:flutter/widgets.dart';
/// A more traditional StreamBuilder style builder method
class ValueObservableBuilder<T> extends StreamBuilder<T> {
ValueObservableBuilder({
Key key,
ValueObservable<T> valueObservable,
AsyncWidgetBuilder<T> builder,
}) : super(key: key, stream: valueObservable, initialData: valueObservable.value, builder: builder);
}
/// One that unwraps the value immediately
class ValueObservableBuilder2<T> extends StreamBuilder<T> {
ValueObservableBuilder2({
Key key,
ValueObservable<T> valueObservable,
Widget Function(BuildContext context, T value) builder,
}) : super(
key: key,
stream: valueObservable,
initialData: valueObservable.value,
builder: (BuildContext context, AsyncSnapshot<T> snap) =>
builder(context, snap.data));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment