How to get data from the FutureProvider in flutter

FutureProvider exposes the result of the Future returned by builder to its descendants.

As such, using the following FutureProvider:

  initialData: 0,
  builder: (_) => Future.value(42),
  child: ...

it is possible to obtain the current value through:



  builder: (context, value, __) {
    return Text(value.toString());

In my example I used the create parameter of FutureProvider to request the API, then then I used Consumer to get the results of the API.

        create: (_) => peopleService.getAllSurvivor(),
        child: Consumer<List<Survivor>>(builder: (context, survivors, _) {
          return survivors == null
              ? Center(child: CircularProgressIndicator())
              : ListView.builder(
                  itemCount: survivors.length,
                  itemBuilder: (context, index) {
                    var survivor = survivors[index];
                    return ListTile(
                      title: Text(,
                      subtitle: Text(survivor.gender),
                      leading: Icon(Icons.perm_identity),