getTotalColumnCount static method
筛选项最多不超过三层,故直接写代码判断,本质为深度优先搜索。
Implementation
static int getTotalColumnCount(PickerEntity? entity) {
int count = 0;
PickerEntity? rootEntity = entity;
while (rootEntity?.parent != null) {
rootEntity = rootEntity?.parent!;
}
if (rootEntity != null && rootEntity.children.isNotEmpty) {
count = count > 1 ? count : 1;
for (PickerEntity firstLevelEntity in rootEntity.children) {
if (firstLevelEntity.children.isNotEmpty) {
count = count > 2 ? count : 2;
for (PickerEntity secondLevelEntity in firstLevelEntity.children) {
if (secondLevelEntity.children.isNotEmpty) {
count = 3;
break;
}
}
}
}
}
return count;
}