extended_future_builder 0.1.1

Flutter Android iOS web

A FutureBuilder with retry and separated builders for success, loading, empty and error situations.

Extended Future Builder #

A FutureBuilder with some cool options

  • Tap to retry the future on case of error
  • builders for future loading, error and success

Why #

After using Future Builder a lot for http requests, I realized that it was possible to simplify the necessary work a little. Thus was born this library, where there is a separation of the builder functions in: success, loading, emptiness and error. It is also possible, in case of Future error, to click on the widget to try to load Future again, which is very useful in http requests that may have failed due to user's Internet related problems.

Parameters #

parameterdescriptiondefault
futureResponseBuilderBuilder responsible for return the future. Used on initState and on retry.required
successBuilderBuilder responsible for return the widget when Future was geted successful and have any data.required
loadingBuilderBuilder responsible for return the widget while Future aren't ready.Center(child: CircularProgressIndicator());
emptyBuilderBuilder responsible for return the widget when Future was geted successful and have no data.
errorBuilderBuilder responsible for return the widget when Future was geted unsuccessful.
ftrStartedCallback for the moment of creation of Future.
ftrThenCallback for Future success.
ftrCatchCallback for Future error.
allowRetryIndicates if user can tap on widget of error for build a new Future and try again.true

Example #

ExtendedFutureBuilder<User>(
        futureResponseBuilder: () => service.getUser(userId),
        ftrStarted: () {
          title = 'Loading...';
        },
        ftrThen: (user) {
          setState(() {
            title = 'Hi ${user.name}';
          });
        },
        ftrCatch: (err) {
          setState(() {
            title = 'Error :(';
          });
        },
        errorBuilder: (BuildContext context, error) {
          return Center(
            child: Text('An error has occurred. Tap to try again.'),
          );
        },
        successBuilder: (BuildContext context, User user) {
          return Text('Good morning ${user.name}');
        },
      ),
2
likes
110
pub points
29%
popularity

Publisher

unkapps.com

A FutureBuilder with retry and separated builders for success, loading, empty and error situations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on extended_future_builder