最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

redux - Flutter async_redux - Upgrade from 20.0.2 to 23.2.0 the didUpdateWidget is no longer called - Stack Overflow

programmeradmin0浏览0评论

We recently updated from version 20.0.2 to version 23.2.0 of async_redux on Flutter Web, and we noticed that with this update now every time a variable inside the state that is used in the viewmodel in a StoreConnector page (StatelessWidget) is updated, the initState of the child (StatefulWidget) is always called and no longer the didUpdateWidget.

class ModalContainer extends StatelessWidget {
  ModalContainer() : super(key: UniqueKey());

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, ViewModel>(
      vm: () => Factory(this),
      builder: (BuildContext context, ViewModel vm) {
        return StatefulWidgetModal(
          vm.stateVariable,
        );
      },
    );
  }
}

class ViewModel extends Vm {
  final List<stateVariable>? stateVariable;

  ViewModel({
    this.stateVariable,
  }) : super(equals: <Object?>[stateVariable]);
}

class Factory extends VmFactory<AppState, ModalContainer, ViewModel> {
  Factory(ModalContainer connector) : super(connector);

  @override
  ViewModel fromStore() => ViewModel(
        stateVariable: state.testState.stateVariable,
      );
}

After we call this action (DataAction), in the StatefulWidgetModal widget the initState now is always called. Before the update the didUpdateWidget was called.

class DataAction extends ReduxAction<AppState> {
  DataAction();

  @override
  Future<AppState?> reduce() async {
    return state.copy(
        testState: state.testState.copyWith(
      stateVariable: "updateValue",
    ));
  }
}

We searched through old issues and changelogs but we found nothing about this change/issue.

I also tried adding the flags: distinct: true. But as soon as an action is called the whole widget is rebuilt even if the state is not updated.

发布评论

评论列表(0)

  1. 暂无评论