1、引入依赖
city_pickers: ^0.1.28 #省市县
2、页面的demo
bool customerItemBuilder = true;//是否自定义类型
void _toAddress(Action action, Context<AddressAddState> ctx) async{
double customerItemExtent = 40;
PickerItem themeAttr;
PickerItem showTypeAttr = PickerItem(name: '省+市+县', value: ShowType.pca);
Result resultAttr = new Result();
Result result = new Result();
double barrierOpacityAttr = 0.5;
bool barrierDismissibleAttr = false;
bool customerMeta = false;
bool customerButtons = true;
bool isSort = false;
Result tempResult = await CityPickers.showCityPicker(
context: ctx.context,
theme: themeAttr != null ? themeAttr.value : null,
locationCode: resultAttr != null
? resultAttr.areaId ??
resultAttr.cityId ??
resultAttr.provinceId
: null,
showType: showTypeAttr.value,
isSort: true,
barrierOpacity: barrierOpacityAttr,
barrierDismissible: barrierDismissibleAttr,
citiesData: null,
provincesData: null,
height: 250,
itemExtent: customerItemExtent,
cancelWidget: customerButtons ? Text('取消',style: TextStyle(fontSize: 18.0,color: Public().COLOR_THEME),) : null,
confirmWidget: customerButtons ? Text('确认',style:TextStyle(fontSize: 18.0,color: Public().COLOR_THEME),) : null,
itemBuilder: getItemBuilder());
if(tempResult!=null){
String address = tempResult.provinceName+" "+tempResult.cityName+" "+tempResult.areaName;
ctx.dispatch(AddressAddActionCreator.onUpdateAddress(address));
}
}
getItemBuilder() {
if (customerItemBuilder) {
return (item, list, index) {
return Center(
child: Text(item, maxLines: 1, style: TextStyle(fontSize: 18.0)));
};
} else {
return null;
}
}