Closed beydeng closed 4 years ago
indexPage中如下
class IndexPage extends Page<IndexState, Map<String, dynamic>> {
IndexPage()
: super(
initState: initState,
effect: buildEffect(),
reducer: buildReducer(),
view: buildView,
dependencies: Dependencies
}
是因为 HomeConnector 连接器链接之后,只能在indexpage里面去操作homepage的state么?
经过几天摸索,研究出来了问题。主要就是连接器不是很明白导致的问题。这里给有相同问题的同性朋友说下问题所在。 只要把状态state交给IndexState来管理的,然后在IndexState中的连接器中进行处理,就可以解决这个问题。 class HomeConnector extends ConnOp<IndexState, HomeState> { @override HomeState get(IndexState state) { if(state.homeState == null){ state.homeState = HomeState() ..recommandDatas=[] ..categoryDatas=[] ..goodsList = []; }
return state.homeState;
}
@override
List
@override
void set(IndexState state, HomeState subState) {
state.homeState = subState;
}
}
@beydeng 牛批。兄弟,你是怎么摸索出来的。
如我在indexpage里面 void _init(Action action, Context ctx) async {
dynamic pageList = [
keepAliveWrapper(
ctx.buildComponent('homePage'),
),
...
}
实例化pageList,里面放如多个page,如上的homePage
然后使用在indexpage中
child: PageView(
scrollDirection: Axis.horizontal,
children: state.pageList,
controller: state.scrollController,
physics: NeverScrollableScrollPhysics(),
),
虽然这样可以加载page显示UI,如homePage可以正常显示,
class HomePage extends Page<HomeState, Map<String, dynamic>> { HomePage() : super( initState: initState, effect: buildEffect(), reducer: buildReducer(), view: buildView, dependencies: Dependencies(
adapter: null,
slots: <String, Dependent>{
'topBar': TopBarConnector() + TopBarComponent(),
'sectionBar': SectionBarConnector() + SectionBarComponent()
}),
middleware: <Middleware>[
],);
}
但是 在homePage里面的initState方法里面,发现如下initState方法并不会走,也就是这样的话HomePage的state无法实例化。请教下原因是什么?如何解决这个问题。
HomeState initState(Map<String, dynamic> args) {
print('initState has runing');
return HomeState() ..isBackIconShow = false ..themeColor = Colors.blue ..rightTitle = '' ..categoryDatas = List();
}