How to get data from the FutureProvider in flutter

后端 未结 2 2131
伪装坚强ぢ
伪装坚强ぢ 2021-02-15 13:21

I\'m trying to implement local database support in my flutter app which is being managed using Provider, now I want to make the retrieving of data obey the state management patt

2条回答
  •  南方客
    南方客 (楼主)
    2021-02-15 13:56

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

    As such, using the following FutureProvider:

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

    it is possible to obtain the current value through:

    Provider.of(context)
    

    or:

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

提交回复
热议问题