snapshot_helper 1.0.0

Flutter Android iOS web

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 returned
  • dataPredicate: predicate to determine when the data widget has to be returned
  • errorPredicate: 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 builder
  • onData: data widget builder
  • onError: error widget builder
  • defaultWidget: 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.

3
likes
100
pub points
16%
popularity

Publisher

magicleon94.dev

A simple helper to manage widget output from the AsyncSnapshot of a stream.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on snapshot_helper