flutter_data_state 0.3.1 copy "flutter_data_state: ^0.3.1" to clipboard
flutter_data_state: ^0.3.1 copied to clipboard

DataStateBuilder and other data_state Flutter utilities

flutter_data_state #

DataStateBuilder and other data_state Flutter utilities.

👩🏾‍💻 Usage #

@override
Widget build(BuildContext context) {
  return DataStateBuilder<String>(
    notifier: notifierCallback,
    builder: (context, state, notifier, _) {
      return RefreshIndicator(
        onRefresh: notifier.reload,
        child: ListView(
          children: [
            if (state.isLoading) CircularProgressIndicator(),
            if (state.hasException) ExceptionWidget(state.exception.toString()),
            if (state.hasModel) ModelWidget(state.model),
          ],
        ),
      );
    },
  );
}

where notifierCallback is a DataStateNotifier Function() void callback.

Examples:

  • () => repository.watchAll()
  • (() => future).asDataNotifier
  • (() => stream).asDataNotifier

Memoization #

All notifiers are passed in VoidCallbacks. They are memoized by default. If you don't want this, pass memoize: false (or control the behavior with key).

@override
Widget build(BuildContext context) {
  return DataStateBuilder<String>(
    notifier: notifierCallback
    memoize: false, // defaults to true
    key: Key(key), // optional
    builder: (context, state, notifier, _) {
      // ...
    },
  );
}

➕ Collaborating #

Please use Github to ask questions, open issues and send PRs. Thanks!

📝 License #

See LICENSE

0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

DataStateBuilder and other data_state Flutter utilities

Homepage
Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

data_state, flutter, flutter_state_notifier

More

Packages that depend on flutter_data_state