brianegan/flutter_redux

flutter redux setState will call oninit function and refresh page again

wangxingxing123654 opened this issue · 1 comments

` Container(
child: StoreConnector<AppState, CollectionState>(
onInit: (store) async {
await loadMoreData(
page: currentPage, extra: {"sorts": sortValue});
},
distinct: true,
converter: (store) {
return store.state.collectionData;
},

            builder: (BuildContext context, collectionState) {
              collectionProduct = collectionState?.collectionData?.data;
              collectionInfo = collectionState?.collectionData?.collection;
              int totalResults =
                  collectionState?.collectionData?.meta?.pagination?.total;
              return Column(children: [
                _renderCollectionHeader(collectionInfo, totalResults),
                _renderCollectionContent(collectionProduct)
              ]);
            },`

when i setState, the oninit function will call again ,call api and refresh the page ,how to avoid this
?

Odd -- Flutter should detect this Widget has not changed and reuse it, but in cases where it cannot do that, you must supply a Key to the StoreConnector Widget. That way Flutter will compare keys, see they're the same, and it shouldn't rebuild the whole thing.