fromSelectedIndex<T extends BaseCityModel<T>> static method
AreaPickerAddressModel
fromSelectedIndex<
T extends BaseCityModel<T>>({ - required List<T> provinceModels,
- required List<T> cityModels,
- required List<T> districtModels,
- required bool shouldAddAllProvinceItem,
- required bool shouldAddAllCityItem,
- required bool shouldAddAllAreaItem,
- required int proviceIndex,
- required int cityIndex,
- required int districtIndex,
})
Implementation
static AreaPickerAddressModel fromSelectedIndex<T extends BaseCityModel<T>>({
required List<T> provinceModels,
required List<T> cityModels,
required List<T> districtModels,
required bool shouldAddAllProvinceItem,
required bool shouldAddAllCityItem,
required bool shouldAddAllAreaItem,
required int proviceIndex,
required int cityIndex,
required int districtIndex,
}) {
String provinceName;
String provinceCode;
if (shouldAddAllProvinceItem) {
if (proviceIndex == 0) {
provinceName = "全部";
provinceCode = "999999";
} else {
T model = provinceModels[proviceIndex - 1];
provinceName = model.regionName;
provinceCode = model.regionId.toString();
}
} else {
T model = provinceModels[proviceIndex];
provinceName = model.regionName;
provinceCode = model.regionId.toString();
}
String cityName;
String cityCode;
if (shouldAddAllCityItem) {
if (cityIndex == 0) {
cityName = "全部";
cityCode = "999999";
} else {
T model = cityModels[cityIndex - 1];
cityName = model.regionName;
cityCode = model.regionId.toString();
}
} else {
T model = cityModels[cityIndex];
cityName = model.regionName;
cityCode = model.regionId.toString();
}
String areaName;
String areaCode;
if (shouldAddAllAreaItem) {
if (districtIndex == 0) {
areaName = "全部";
areaCode = "999999";
} else {
T model = districtModels[districtIndex - 1];
areaName = model.regionName;
areaCode = model.regionId.toString();
}
} else {
T model = districtModels[districtIndex];
areaName = model.regionName;
areaCode = model.regionId.toString();
}
String address = provinceName;
if (cityName != "全部") {
address += " $cityName";
}
if (areaName != "全部") {
address += " $areaName";
}
return AreaPickerAddressModel(
provinceName: provinceName,
provinceCode: provinceCode,
cityName: cityName,
cityCode: cityCode,
areaName: areaName,
areaCode: areaCode,
address: address,
provinceIndex: proviceIndex,
cityIndex: cityIndex,
areaIndex: districtIndex,
);
}