snapshot_helper 1.0.1
snapshot_helper: ^1.0.1 copied to clipboard
A simple helper to manage widget output from the AsyncSnapshot of a stream.
snapshot_helper #
A simple helper to manage widget output from the AsyncSnapshot of a stream.
Basic usage #
Instantiate the helper from an AsyncSnapshot<T>
and the call getWidget
specifying the builders for different situations:
StreamBuilder(
stream: streamController.stream,
builder: (context, snapshot) =>
SnapshotHelper.of(snapshot).getWidget(
onData: (snapshot) => DataWidget(),
onLoading: (snapshot) => LoadingWidget(),
onError: (snapshot) => ErrorWidget(),
),
)
Constructor parameters #
loadingPredicate
: predicate to determine when the loading widget has to be returneddataPredicate
: predicate to determine when the data widget has to be returnederrorPredicate
: predicate to determine when the error widget has to be returned
The predicates are optional and should be supplied only when in need of more custom scenarios.
getWidget parameters #
onLoading
: loading widget builderonData
: data widget builderonError
: error widget builderdefaultWidget
: placeholder widget in case no state is matched by the predicates
Subclassing #
You can extend
the SnapshotHelper
class in order to have you own custom rules too.