From aeea5160861b688f6e4dc2c0aecb7dc71f093434 Mon Sep 17 00:00:00 2001 From: "sanfan.hx" Date: Mon, 25 Feb 2019 10:24:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(=E5=A4=84=E7=90=86=E5=85=A8=E5=B1=8F?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=99=A8=E4=B8=8B=E7=9A=84.=20=E5=8C=BA?= =?UTF-8?q?=E7=BA=A7=E6=97=A0=E6=95=B0=E6=8D=AE=E7=9A=84bug):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/base/base.dart | 18 ++++++++---- lib/src/full_page/full_page.dart | 49 +++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/lib/src/base/base.dart b/lib/src/base/base.dart index 2b797bf..69060ce 100644 --- a/lib/src/base/base.dart +++ b/lib/src/base/base.dart @@ -8,11 +8,12 @@ */ import 'dart:async'; -import 'package:flutter/material.dart'; +import 'package:city_pickers/modal/base_citys.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + import '../../modal/point.dart'; import '../../modal/result.dart'; -import 'package:city_pickers/modal/base_citys.dart'; import '../mod/inherit_process.dart'; import '../show_types.dart'; @@ -117,7 +118,7 @@ class _BaseView extends State { targetProvince.child.forEach((Point _city) { if (_city.code == _locationCode) { targetCity = _city; - targetArea = _getTargetChildFirst(_city) ?? null; + targetArea = _getTargetChildFirst(_city); } _city.child.forEach((Point _area) { if (_area.code == _locationCode) { @@ -210,6 +211,7 @@ class _BaseView extends State { }); }); } + Result _buildResult() { Result result = Result(); ShowType showType = widget.showType; @@ -218,12 +220,18 @@ class _BaseView extends State { result.provinceName = targetProvince.name; } if (showType.contain(ShowType.c)) { + result.provinceId = targetProvince.code.toString(); + result.provinceName = targetProvince.name; result.cityId = targetCity != null ? targetCity.code.toString() : null; result.cityName = targetCity != null ? targetCity.name : null; } if (showType.contain(ShowType.a)) { + result.provinceId = targetProvince.code.toString(); + result.provinceName = targetProvince.name; + result.cityId = targetCity != null ? targetCity.code.toString() : null; + result.cityName = targetCity != null ? targetCity.name : null; result.areaId = targetArea != null ? targetArea.code.toString() : null; - result.areaName = targetArea != null ? targetArea.name : null; + result.areaName = targetArea != null ? targetArea.name : null; } // 台湾异常数据. 需要过滤 if (result.provinceId == "710000") { @@ -293,7 +301,7 @@ class _BaseView extends State { isShow: widget.showType.contain(ShowType.c), controller: cityController, height: widget.height, - value: targetCity == null ? null :targetCity.name , + value: targetCity == null ? null : targetCity.name, itemList: getCityItemList(), changed: (index) { _onCityChange(targetProvince.child[index]); diff --git a/lib/src/full_page/full_page.dart b/lib/src/full_page/full_page.dart index 657d33a..ff3db61 100644 --- a/lib/src/full_page/full_page.dart +++ b/lib/src/full_page/full_page.dart @@ -7,13 +7,15 @@ // tartget: xxx // -import 'package:flutter/material.dart'; -import 'package:city_pickers/modal/point.dart'; +import 'dart:async'; + import 'package:city_pickers/modal/base_citys.dart'; -import 'package:city_pickers/src/show_types.dart'; +import 'package:city_pickers/modal/point.dart'; import 'package:city_pickers/modal/result.dart'; +import 'package:city_pickers/src/show_types.dart'; import 'package:city_pickers/src/util.dart'; -import 'dart:async'; +import 'package:flutter/material.dart'; + class FullPage extends StatefulWidget { final String locationCode; final ShowType showType; @@ -113,7 +115,7 @@ class _FullPageState extends State { targetProvince.child.forEach((Point _city) { if (_city.code == _locationCode) { targetCity = _city; - targetArea = _city.child.first ?? null; + targetArea = _getTargetChildFirst(_city) ?? null; } _city.child.forEach((Point _area) { if (_area.code == _locationCode) { @@ -127,10 +129,10 @@ class _FullPageState extends State { } if (targetCity == null) { - targetCity = targetProvince.child.first ?? Point(); + targetCity = _getTargetChildFirst(targetProvince); } if (targetArea == null) { - targetArea = targetCity.child.first ?? Point(); + targetArea = _getTargetChildFirst(targetCity); } } @@ -143,12 +145,18 @@ class _FullPageState extends State { result.provinceName = targetProvince.name; } if (showType.contain(ShowType.c)) { - result.cityId = targetCity.code.toString(); - result.cityName = targetCity.name; + result.provinceId = targetProvince.code.toString(); + result.provinceName = targetProvince.name; + result.cityId = targetCity != null ? targetCity.code.toString() : null; + result.cityName = targetCity != null ? targetCity.name : null; } if (showType.contain(ShowType.a)) { - result.areaId = targetArea.code.toString(); - result.areaName = targetArea.name; + result.provinceId = targetProvince.code.toString(); + result.provinceName = targetProvince.name; + result.cityId = targetCity != null ? targetCity.code.toString() : null; + result.cityName = targetCity != null ? targetCity.name : null; + result.areaId = targetArea != null ? targetArea.code.toString() : null; + result.areaName = targetArea != null ? targetArea.name : null; } } catch (e) { // 此处兼容, 部分城市下无地区信息的情况 @@ -164,6 +172,16 @@ class _FullPageState extends State { return result; } + Point _getTargetChildFirst(Point target) { + if (target == null) { + return null; + } + if (target.child != null && target.child.isNotEmpty) { + return target.child.first; + } + return null; + } + popHome() { Navigator.of(context).pop(_buildResult()); } @@ -218,6 +236,11 @@ class _FullPageState extends State { if (!widget.showType.contain(ShowType.c)) { nextStatus = Status.Over; } + if (nextItemList.isEmpty) { + targetCity = null; + targetArea = null; + nextStatus = Status.Over; + } break; case Status.City: _onCitySelect(targetPoint); @@ -226,6 +249,10 @@ class _FullPageState extends State { if (!widget.showType.contain(ShowType.a)) { nextStatus = Status.Over; } + if (nextItemList.isEmpty) { + targetArea = null; + nextStatus = Status.Over; + } break; case Status.Area: nextStatus = Status.Over; From fa0d82a13cf687199d8eac5edd64c1541de3a15e Mon Sep 17 00:00:00 2001 From: "sanfan.hx" Date: Mon, 25 Feb 2019 11:05:19 +0800 Subject: [PATCH 2/2] updat: version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index cfc85b4..2b95083 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: city_pickers description: Flutter plugin for city picker, Popups widgets, call by function, supoort china areas for the moment. -version: 0.1.10 +version: 0.1.11 author: sanfan.hx homepage: https://github.com/hanxu317317/city_pickers