【问题标题】:flutter redux setState will call oninit function and refresh page again #189flutter redux setState 会调用 oninit 函数并再次刷新页面 #189
【发布时间】:2020-08-21 06:43:10
【问题描述】:
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)
              ]);
            },

当我setState时,oninit函数会再次调用,调用api并刷新页面,如何避免这种情况

【问题讨论】:

  • loadMoreData 是一个从后端数据库获取数据的函数;

标签: flutter flutter-redux


【解决方案1】:

我认为你在使用 redux 状态时不应该使用 setState。进行相应的更改。

【讨论】:

    猜你喜欢
    • 2021-03-02
    • 2020-12-05
    • 2012-03-01
    • 1970-01-01
    • 2020-12-21
    • 2018-01-21
    • 1970-01-01
    • 2022-07-23
    • 1970-01-01
    相关资源
    最近更新 更多