需要使用带有flutter的回调函数通过redux进行重建

时间:2019-01-29 21:18:32

标签: redux dart flutter

我正在创建一个具有StoreConnect的窗口小部件,它调用另一个类似于动画的窗口小部件,但是它具有回调函数,当使用该回调函数时,将不应用redux状态。 我的意思是,redux状态已更改,再次构建了小部件,但回调函数未更改。

这是我的小部件:

@override
Widget build(BuildContext context) {
  return new StoreConnector<ReduxState, PlaceCardViewModel>(
    converter: (store) {
      return new PlaceCardViewModel(
          currentUserPlace: store.state.currentUserPlace,
          onUserPlaceRatingChanged: (isRatingPlace) =>
              store.dispatch(new SetUserPlaceRating(isRatingPlace)),
          onCurrentUserPlaceChanged: (currentUserPlace) =>
              store.dispatch(new SetCurrentUserPlace(currentUserPlace)),
          onCurrentPlaceProfileChanged: (currentPlaceProfile) => store
              .dispatch(new SetCurrentPlaceProfile(currentPlaceProfile)));
    },
    builder: (context, vm) {
      return HighLightAnimation(this._getCard(vm), onLongPressCallback: () {
        if (vm.currentUserPlace != null) {
          print('IT WORKS!!!');
        }
        this._onPlaceCardActions(vm, context);
      });
    },
  );
}

它以这种方式工作,没有回调:

@override
Widget build(BuildContext context) {
  return new StoreConnector<ReduxState, PlaceCardViewModel>(
    converter: (store) {
      return new PlaceCardViewModel(
          currentUserPlace: store.state.currentUserPlace,
          onUserPlaceRatingChanged: (isRatingPlace) =>
              store.dispatch(new SetUserPlaceRating(isRatingPlace)),
          onCurrentUserPlaceChanged: (currentUserPlace) =>
              store.dispatch(new SetCurrentUserPlace(currentUserPlace)),
          onCurrentPlaceProfileChanged: (currentPlaceProfile) => store
              .dispatch(new SetCurrentPlaceProfile(currentPlaceProfile)));
    },
    builder: (context, vm) {
      Column(
        children: <Widget>[
          this._getCard(vm),
          RaisedButton(
            child: Text('Click me!'),
            onPressed: () {
              if (vm.currentUserPlace != null) {
                print('ON PRESSED WORKS FINE');
              }
              this._onPlaceCardActions(vm, context);
            },
          )
        ],
      );
    },
  );
}

0 个答案:

没有答案