getLabels method

String getLabels(
  1. String level0,
  2. String level1,
  3. String level2
)

Implementation

String getLabels(String level0, String level1, String level2) {
  List labels = [];
  cacheItems = [];
  cachePageItems = [];
  // 省
  CityModel item0 = records.firstWhere(
    (element) => element.areaCode.toString() == level0,
    orElse: () {
      return CityModel.fromParams();
    },
  );
  if (!DartHelper.isNullOrEmpty(item0.label)) {
    cachePageItems.add(records);
    labels.add(item0.label);
    cacheItems.add(item0);
    if (item0.children != null) {
      cachePageItems.add(item0.children);
    }
  }
  // 市
  CityModel item1 = item0.children.firstWhere(
    (element) => element.areaCode.toString() == level1,
    orElse: () {
      return CityModel.fromParams();
    },
  );
  if (!DartHelper.isNullOrEmpty(item1.label)) {
    labels.add(item1.label);
    cacheItems.add(item1);
    if (item1.children != null) {
      cachePageItems.add(item1.children);
    }
  }
  // 区
  CityModel item2 = item1.children.firstWhere(
    (element) => element.areaCode.toString() == level2,
    orElse: () {
      return CityModel.fromParams();
    },
  );
  if (!DartHelper.isNullOrEmpty(item2.label)) {
    labels.add(item2.label);
    cacheItems.add(item2);
    if (item2.children != null) {
      cachePageItems.add(item2.children);
    }
  }
  return labels.join("/");
}