extended_future_builder 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new56

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}');
        },
      ),

[0.0.1] #

  • Initial release

[0.0.2] #

  • Add pedantic to increase maintainability

[0.1.0] #

  • Add example

[0.1.1] #

  • Improve readme

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:example/home/home_page.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Extended Future Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: HomePage(),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  extended_future_builder: ^0.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:extended_future_builder/extended_future_builder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
12
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
56
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [extended_future_builder] that is in a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
pedantic ^1.8.0