Closed jing-pei closed 4 years ago
Effect<HomeListState> buildEffect() {
return combineEffects(<Object, Effect<HomeListState>>{
Lifecycle.initState: _onInit,
Lifecycle.dispose: _onDispose,
});
}
不知道 我这种方法是否正确,应该在哪里进行 ctx.state.scrollController?.addListener
另外我在组件implements StateKey 依然存在该问题
@override
Object key() {
return uniqueKey;
}
1、生命周期都是透传,所以生命周期问题,是flutter内部实现如此; 2、Connector 冗余
// Connerctor (其他类似)
class MyConnector extends ConnOp<HomeState, HomeListState> {
final String type;
const MyConnector(this.type);
@override
HomeListState get(HomeState state) {
// tabViewList 在State中的声明==》 Map<TabType, HomeListState> tabViewList = {};
return state.tabViewList[type];
}
@override
void set(HomeState state, HomeListState subState) {
state.tabViewList[type] = subState;
}
}
即可
非常感谢,我已测试,是flutter自身的问题
异常情况 当我在TabbarView的每个Tab页面嵌套一个Component时(4个),如果非连续切换,会多次进入 Lifecycle.initState: _onInit, Lifecycle.dispose: _onDispose,
测试结果: ---0---1---2---3 当我直接点击tagIndex=3时,会有如下周期: flutter: Lifecycle.initState: tagIndex = 0 flutter: Lifecycle.initState: tagIndex = 2 flutter: Lifecycle.dispose: tagIndex = 2 flutter: Lifecycle.initState: tagIndex = 2 flutter: Lifecycle.initState: tagIndex = 3 flutter: Lifecycle.dispose: tagIndex = 2
关键代码
在component的使用
期望 生命周期正常:init对应一个dispose 或者在Tabbar中非相邻切换时Lifecycle能正常