Skip to content

Commit

Permalink
Merge pull request #12 from hanxu317317/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
hanxu317317 authored Feb 25, 2019
2 parents e245701 + 6c3c757 commit e73c8be
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
18 changes: 13 additions & 5 deletions lib/src/base/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -117,7 +118,7 @@ class _BaseView extends State<BaseView> {
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) {
Expand Down Expand Up @@ -210,6 +211,7 @@ class _BaseView extends State<BaseView> {
});
});
}

Result _buildResult() {
Result result = Result();
ShowType showType = widget.showType;
Expand All @@ -218,12 +220,18 @@ class _BaseView extends State<BaseView> {
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") {
Expand Down Expand Up @@ -293,7 +301,7 @@ class _BaseView extends State<BaseView> {
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]);
Expand Down
49 changes: 38 additions & 11 deletions lib/src/full_page/full_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,7 +115,7 @@ class _FullPageState extends State<FullPage> {
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) {
Expand All @@ -127,10 +129,10 @@ class _FullPageState extends State<FullPage> {
}

if (targetCity == null) {
targetCity = targetProvince.child.first ?? Point();
targetCity = _getTargetChildFirst(targetProvince);
}
if (targetArea == null) {
targetArea = targetCity.child.first ?? Point();
targetArea = _getTargetChildFirst(targetCity);
}
}

Expand All @@ -143,12 +145,18 @@ class _FullPageState extends State<FullPage> {
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) {
// 此处兼容, 部分城市下无地区信息的情况
Expand All @@ -164,6 +172,16 @@ class _FullPageState extends State<FullPage> {
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());
}
Expand Down Expand Up @@ -218,6 +236,11 @@ class _FullPageState extends State<FullPage> {
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);
Expand All @@ -226,6 +249,10 @@ class _FullPageState extends State<FullPage> {
if (!widget.showType.contain(ShowType.a)) {
nextStatus = Status.Over;
}
if (nextItemList.isEmpty) {
targetArea = null;
nextStatus = Status.Over;
}
break;
case Status.Area:
nextStatus = Status.Over;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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<[email protected]>
homepage: https://github.com/hanxu317317/city_pickers

Expand Down

0 comments on commit e73c8be

Please sign in to comment.