flutter 省市區選擇器 city_pickers 的簡單實用


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 版本之前無法使用自定義確定取消按鈕

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM