Github地址:https://github.com/hanxu317317/city_pickers
packages地址: https://pub.flutter-io.cn/packages/city_pickers#-readme-tab-
1、將其添加到包的pubspec.yaml文件中,並下載:
city_pickers: ^0.1.18
2、在需要使用的文件導入
import 'package:city_pickers/city_pickers.dart';
3、使用(在這只貼方法)
Result resultArr = new Result(); void _clickEventFunc() async{ Result tempResult = await CityPickers.showCityPicker( context: context, theme: Theme.of(context).copyWith(primaryColor: Color(0xfffe1314)), // 設置主題 locationCode: resultArr != null ? resultArr.areaId ?? resultArr.cityId ?? resultArr.provinceId : null, // 初始化地址信息 cancelWidget: Text( '取消', style: TextStyle(fontSize: ScreenUtil().setSp(26),color: Color(0xff999999)), ), confirmWidget: Text( '確定', style: TextStyle(fontSize: ScreenUtil().setSp(26),color: Color(0xfffe1314)), ), height: 220.0 ); if(tempResult != null){ setState(() { resultArr = tempResult; }); } }
因項目和時間的原因,只使用了 showCityPicker 方法,可自行嘗試下面兩種選擇方式。
// type 2 Result result2 = await CityPickers.showFullPageCityPicker( context: context, ); // type 3 Result result2 = await CityPickers.showCitiesSelector( context: context, );
注:
在 0.1.18 版本之前無法使用自定義確定取消按鈕