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

如何在一个Page中注册两个tickerProvider #564

Closed Muzm closed 4 years ago

Muzm commented 4 years ago

目前的需求是两个嵌套在一起的Tabar在同一个Page下. 两个Tabbar需要两个TickerProvider. 来进行一些滚动监听实现. 我的Page代码如下:

class _HomeTabControlState extends ComponentState<MallHomeState>
    with TickerProviderStateMixin  {}

class _HomeRecommendControlState extends ComponentState<MallHomeState>
    with TickerProviderStateMixin  {}

class MallHomePage extends Page<MallHomeState, Map<String, dynamic>> {
  MallHomePage()
      : super(
          initState: initState,
          effect: buildEffect(),
          reducer: buildReducer(),
          view: buildView,
          dependencies: Dependencies<MallHomeState>(
              adapter: null, slots: <String, Dependent<MallHomeState>>{}),
          middleware: <Middleware<MallHomeState>>[],
        );

  @override
  _HomeTabControlState createState() {
    return _HomeTabControlState();
  }
}

请问如何在Page中注册多个TickerProviderStateMixin ?

VintLin commented 4 years ago

你不能在page里获取的ticker保存在state中,再传递给component吗?

Muzm commented 4 years ago

抱歉这么晚回复. 现在不是传值的问题是将一个Ticker给两个TabController使用时就会报错. 整个页面会出现黑屏. 下面是我注册两个TabController的代码. 所以问题是如何在一个Page中注册两个Ticker.

void _initState(Action action, Context<MallHomeState> ctx) {

  TabController controller;

  final TickerProvider tickerProvider = ctx.stfState as TickerProvider;
  controller = TabController(length: 5, vsync: tickerProvider);
  ctx.dispatch(MallHomeActionCreator.pageControllerInit(controller));

  final TickerProvider tickerProvider2 = ctx.stfState as TickerProvider;
  controller = TabController(length: 3, vsync: tickerProvider2);
  ctx.dispatch(MallHomeActionCreator.recommendControllerInit(controller));
}
Muzm commented 4 years ago

目前没有找到能在一个Page中注册两个Ticker的方法. 我的替代方案是创建两个Page, 每个Page中都注册一个Ticker.