void updateSectionState(String key, PowerSectionState state) {
final SectionData data = _dataCenter.findSectionByKey(key);
if (state == PowerSectionState.loading) {
// 从ViewCenter的config获取loadingWidget
final Widget loadingWidget = _viewCenter?.config?.loadingWidgetBuilder(this, key, data);
// ViewCenter调用replace section方法更新UI
_viewCenter.replaceSectionOfIndex(loadingWidget);
// 标记需要刷新Section
data.needRefreshWhenComplete = true;
} else if (state == PowerSectionState.error) {
...
} else if (state == PowerSectionState.noMore) {
...
} else if (state == PowerSectionState.complete) {
if (data.needRefreshWhenComplete ?? false) { // 判断是否需要更新Section
final int index = _dataCenter.fineSectionIndexByKey(key);
if (index != null) {
final SectionData sectionData = _dataCenter.containerModel.sections[index];
final PowerSection section = _viewCenter.initSection(sectionData);
_viewCenter.replaceSectionOfIndex(index, section);
}
data.needRefreshWhenComplete = false;
}
}
}
void replaceSections(List<dynamic> sections) {
if (sections == null || sections.isEmpty || _dataCenter?.containerModel?.sections == null) {
return;
}
for (int i = 0; i < sections.length; i++) {
SectionData replaceData = sections[i];
assert(replaceData.slot != null);
// 寻找Section list中与Slot匹配的index
int slotIndex = _findSlot(replaceData);
// 更新dataCenter
_dataCenter.replaceSectionData(slotIndex, replaceData);
// SectionData 转换为PowerScrollView所需的PowerSection
final PowerSection sectionData = _viewCenter?.convertComponentDataToSection(replaceData);
// 更新viewCenter
_viewCenter?.replaceSectionOfIndex(slotIndex, sectionData);
//将替换Section的Restart事件发送到event center
sendEventRestart(replaceData.key);
}
}
PICK ME
闲鱼技术团队通过创新追寻更多价值,不断驱动业务变革。
从闲置生意的老本行,到打造“无忧购”“会玩社区““新线下”,
从出版书籍、峰会发声,到开源专利、海外传播,
闲不住,上闲鱼——技术团队对极致的探索与深耕是我们的底气。
立即加入
1、招客户端/服务端/前端/架构/质量工程师
2、发简历给guicai.gxy@alibaba-inc.com
3、您还可以在头条、知乎、掘金、facebook、twitter找到我们