alibaba / fish-redux

An assembled flutter application framework.
https://github.com/alibaba/fish-redux
Apache License 2.0
7.33k stars 843 forks source link

自定义state继承SingleTickerProviderStateMixin后,action就无法传递到父page #668

Closed ykrank closed 4 years ago

ykrank commented 4 years ago

Describe the bug A clear and concise description of what the bug is. Show the code you wrote as completely as possible.

class CustomStfState<T> extends ComponentState<T> with SingleTickerProviderStateMixin {

}

class HomePage extends AppPageBase<HomeState> {
  HomePage()
      : super(
    initState: initState,
    effect: buildEffect(),
          reducer: buildReducer(),
          view: buildView,
    dependencies: Dependencies<HomeState>(adapter: null, slots: {}),
        );

  @override
  ComponentState<HomeState> createState() {
    return CustomStfState<HomeState>();
  }
}

Widget buildView(HomeState state, Dispatch dispatch, ViewService viewService) {
  return Button(
            onPressed: () {
              dispatch(MainActionCreator.onSelectProject());
            }),

class WorkbenchPage extends AppPageBase<WorkbenchState> {
  WorkbenchPage()
      : super(
          initState: initState,
          effect: buildEffect(),
          reducer: buildReducer(),
          view: buildView,
          dependencies: Dependencies<WorkbenchState>(
              slots: <String, Dependent<WorkbenchState>>{}),
          middleware: <Middleware<WorkbenchState>>[],
        );
}

Widget buildView(WorkbenchState state, Dispatch dispatch, ViewService viewService) {
  return Button(
            onPressed: () {
              dispatch(MainActionCreator.onSelectProject());
            }),

HomePage,WorkbenchPagepage均为MainPage下PageView中的子page。但是WorkbenchPagepage可以触发dispatch(MainActionCreator.onSelectProject()),而HomePage无法触发

zjuwjf commented 4 years ago

HomePage,WorkbenchPagepage 与 MainPage 的关系,代码上是怎么表达的?

ykrank commented 4 years ago

问题已解决。应该和SingleTickerProviderStateMixin无关。最终在HomePage使用viewService.broadcast来触发父page MainPage 中的Action。

HomePage,WorkbenchPagepage 与 MainPage 的关系,代码上是怎么表达的?

在MainPage中使用缓存或者new的HomePage,然后直接调用HomePage的buildPage,作为普通的widget使用。