|
|
|
@ -1,14 +1,20 @@
|
|
|
|
|
import 'dart:convert'; |
|
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart'; |
|
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:flutter/services.dart'; |
|
|
|
|
import 'package:huixiang/utils/font_weight.dart'; |
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
|
import 'package:huixiang/view_widget/my_appbar.dart'; |
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
|
|
|
|
|
|
|
|
import '../retrofit/data/ip_data.dart'; |
|
|
|
|
import '../retrofit/retrofit_api.dart'; |
|
|
|
|
|
|
|
|
|
class UnionSelectCity extends StatefulWidget { |
|
|
|
|
final Map<String, dynamic> arguments; |
|
|
|
|
|
|
|
|
|
UnionSelectCity({this.arguments}); |
|
|
|
|
@override |
|
|
|
|
State<StatefulWidget> createState() { |
|
|
|
|
return _UnionSelectCity(); |
|
|
|
@ -18,25 +24,58 @@ class UnionSelectCity extends StatefulWidget {
|
|
|
|
|
class _UnionSelectCity extends State<UnionSelectCity> { |
|
|
|
|
RefreshController refreshController = RefreshController(); |
|
|
|
|
Map<String, dynamic> areaMap; |
|
|
|
|
ApiService apiIpService; |
|
|
|
|
String ipName; |
|
|
|
|
int ipState = 0; |
|
|
|
|
List<String> hotCity = []; |
|
|
|
|
List<String> areaList = []; |
|
|
|
|
final TextEditingController editingController = TextEditingController(); |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
void initState() { |
|
|
|
|
super.initState(); |
|
|
|
|
areaCode(); |
|
|
|
|
queryIpInfo(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void areaCode() async { |
|
|
|
|
void areaCode({String searchTxt}) async { |
|
|
|
|
var value = |
|
|
|
|
await rootBundle.loadString('assets/map_style/chinese_cities.json'); |
|
|
|
|
areaList.clear(); |
|
|
|
|
areaMap = jsonDecode(value); |
|
|
|
|
hotCity = (areaMap["热门城市"] as List).map((e) { |
|
|
|
|
return e["area"].toString(); |
|
|
|
|
}).toList(); |
|
|
|
|
areaMap.remove("热门城市"); |
|
|
|
|
Map<String, dynamic> tempAreaMap = jsonDecode(value); |
|
|
|
|
areaMap.forEach((key, value) { |
|
|
|
|
areaList.add(key); |
|
|
|
|
if (searchTxt != null && searchTxt.trim() != "") |
|
|
|
|
value.forEach((element) { |
|
|
|
|
if (!element["area"].contains(searchTxt)) |
|
|
|
|
(tempAreaMap[key] as List) |
|
|
|
|
.removeWhere((el) => el["area"] == element["area"]); |
|
|
|
|
}); |
|
|
|
|
if (tempAreaMap[key].isNotEmpty) areaList.add(key); |
|
|
|
|
}); |
|
|
|
|
areaMap = tempAreaMap; |
|
|
|
|
setState(() {}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
queryIpInfo() async { |
|
|
|
|
apiIpService = ApiService( |
|
|
|
|
Dio(), |
|
|
|
|
context: context, |
|
|
|
|
isIp: true |
|
|
|
|
); |
|
|
|
|
IpData baseData = await apiIpService.getIpInfo().catchError((onError) {}); |
|
|
|
|
if (baseData != null) { |
|
|
|
|
ipName = baseData.city.replaceAll("市", ""); |
|
|
|
|
if(ipName != widget.arguments["cityName"] ){ |
|
|
|
|
ipState=2; |
|
|
|
|
setState((){}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
return Scaffold( |
|
|
|
@ -70,207 +109,113 @@ class _UnionSelectCity extends State<UnionSelectCity> {
|
|
|
|
|
Expanded(child: searchCityItem()) |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
Padding(padding:EdgeInsets.only(top: 16.h,bottom: 24.h), |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(top: 16.h, bottom: 24.h), |
|
|
|
|
child: Row( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
|
|
|
children: [ |
|
|
|
|
Padding(padding:EdgeInsets.only(right: 10.w), |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(right: 10.w), |
|
|
|
|
child: Text( |
|
|
|
|
"当前位置", |
|
|
|
|
(ipState == 0||ipState == 1) ? "当前位置" : "已选:", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFFA29E9E), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
), |
|
|
|
|
),), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Image.asset( |
|
|
|
|
"assets/image/icon_union_location.webp", |
|
|
|
|
width: 20, |
|
|
|
|
height: 20, |
|
|
|
|
), |
|
|
|
|
Padding(padding:EdgeInsets.only(left:8.w,), |
|
|
|
|
Expanded( |
|
|
|
|
// padding: EdgeInsets.only( |
|
|
|
|
// left: 8.w, |
|
|
|
|
// ), |
|
|
|
|
child: Text( |
|
|
|
|
"当前位置", |
|
|
|
|
(ipState== 1) ? (ipName??""):widget.arguments["cityName"] ?? "", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF4D4D4D), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
), |
|
|
|
|
),), |
|
|
|
|
], |
|
|
|
|
)), |
|
|
|
|
Padding(padding:EdgeInsets.only(bottom: 16.h), |
|
|
|
|
child: Text( |
|
|
|
|
"热门城市", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFFA29E9E), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
), |
|
|
|
|
),), |
|
|
|
|
Padding(padding:EdgeInsets.only(right: 14.h,bottom: 14.h), |
|
|
|
|
child: Row( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
|
children: [ |
|
|
|
|
GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: (){ |
|
|
|
|
Navigator.of(context).pop("上海");}, |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFF7F7F7), |
|
|
|
|
borderRadius: BorderRadius.circular(4), |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric(horizontal:24.w,vertical:5.h), |
|
|
|
|
child: Text( |
|
|
|
|
"上海", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF4D4D4D), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
if(ipState == 2) |
|
|
|
|
Icon( |
|
|
|
|
Icons.gps_fixed, |
|
|
|
|
color: Colors.grey, |
|
|
|
|
size: 18, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
)), |
|
|
|
|
GestureDetector( |
|
|
|
|
if(ipState == 2) |
|
|
|
|
Padding(padding:EdgeInsets.only(left:5.w,right: 12.w), |
|
|
|
|
child:GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: (){ |
|
|
|
|
Navigator.of(context).pop("深圳");}, |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFF7F7F7), |
|
|
|
|
borderRadius: BorderRadius.circular(4), |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric(horizontal:24.w,vertical:5.h), |
|
|
|
|
setState((){ |
|
|
|
|
ipState = 1; |
|
|
|
|
Navigator.of(context).pop(ipName); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: Text( |
|
|
|
|
"深圳", |
|
|
|
|
"重新定位", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF4D4D4D), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
)), GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: (){ |
|
|
|
|
Navigator.of(context).pop("北京");}, |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFF7F7F7), |
|
|
|
|
borderRadius: BorderRadius.circular(4), |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric(horizontal:24.w,vertical:5.h), |
|
|
|
|
child: Text( |
|
|
|
|
"北京", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF4D4D4D), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
)), GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: (){ |
|
|
|
|
Navigator.of(context).pop("广州");}, |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFF7F7F7), |
|
|
|
|
borderRadius: BorderRadius.circular(4), |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric(horizontal:24.w,vertical:5.h), |
|
|
|
|
child: Text( |
|
|
|
|
"广州", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF4D4D4D), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
)), |
|
|
|
|
),) |
|
|
|
|
], |
|
|
|
|
),), |
|
|
|
|
Padding(padding:EdgeInsets.only(right: 14.h,), |
|
|
|
|
child: Row( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
|
children: [ |
|
|
|
|
GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: (){ |
|
|
|
|
Navigator.of(context).pop("成都");}, |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFF7F7F7), |
|
|
|
|
borderRadius: BorderRadius.circular(4), |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric(horizontal:24.w,vertical:5.h), |
|
|
|
|
child: Text( |
|
|
|
|
"成都", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF4D4D4D), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
)), |
|
|
|
|
GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: (){ |
|
|
|
|
Navigator.of(context).pop("杭州");}, |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFF7F7F7), |
|
|
|
|
borderRadius: BorderRadius.circular(4), |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric(horizontal:24.w,vertical:5.h), |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(bottom: 16.h), |
|
|
|
|
child: Text( |
|
|
|
|
"杭州", |
|
|
|
|
"热门城市", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF4D4D4D), |
|
|
|
|
color: Color(0xFFA29E9E), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
)), |
|
|
|
|
GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: (){ |
|
|
|
|
Navigator.of(context).pop("南京");}, |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFF7F7F7), |
|
|
|
|
borderRadius: BorderRadius.circular(4), |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric(horizontal:24.w,vertical:5.h), |
|
|
|
|
child: Text( |
|
|
|
|
"南京", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF4D4D4D), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
)), |
|
|
|
|
GestureDetector( |
|
|
|
|
GridView.builder( |
|
|
|
|
itemCount: hotCity.length, |
|
|
|
|
padding: EdgeInsets.only(right: 14.h, bottom: 14.h), |
|
|
|
|
shrinkWrap: true, |
|
|
|
|
physics: NeverScrollableScrollPhysics(), |
|
|
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( |
|
|
|
|
crossAxisCount: 4, |
|
|
|
|
crossAxisSpacing: 12.w, |
|
|
|
|
mainAxisSpacing: 12.w, |
|
|
|
|
childAspectRatio: 2.5, |
|
|
|
|
), |
|
|
|
|
itemBuilder: (context, index) { |
|
|
|
|
return GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: () { |
|
|
|
|
Navigator.of(context).pop("重庆");}, |
|
|
|
|
Navigator.of(context).pop(hotCity[index]); |
|
|
|
|
setState((){}); |
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFF7F7F7), |
|
|
|
|
borderRadius: BorderRadius.circular(4), |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric(horizontal:24.w,vertical:5.h), |
|
|
|
|
alignment: Alignment.center, |
|
|
|
|
child: Text( |
|
|
|
|
"重庆", |
|
|
|
|
hotCity[index], |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF4D4D4D), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
), |
|
|
|
|
))); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
),) |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Expanded(child: sortList()) |
|
|
|
@ -284,7 +229,7 @@ class _UnionSelectCity extends State<UnionSelectCity> {
|
|
|
|
|
return Container( |
|
|
|
|
height: 36.h, |
|
|
|
|
margin: EdgeInsets.fromLTRB(6.w, 0, 14.w, 0), |
|
|
|
|
padding: EdgeInsets.fromLTRB(0, 6.h, 0, 0), |
|
|
|
|
// padding: EdgeInsets.fromLTRB(0, 6.h, 0, 0), |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFF1F1F1), |
|
|
|
|
borderRadius: BorderRadius.circular(6), |
|
|
|
@ -302,12 +247,14 @@ class _UnionSelectCity extends State<UnionSelectCity> {
|
|
|
|
|
onEditingComplete: () { |
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode()); |
|
|
|
|
}, |
|
|
|
|
controller: editingController, |
|
|
|
|
onChanged: (txt) { |
|
|
|
|
areaCode(searchTxt: txt); |
|
|
|
|
}, |
|
|
|
|
cursorHeight: 25.h, |
|
|
|
|
decoration: InputDecoration( |
|
|
|
|
// contentPadding: EdgeInsets.symmetric( |
|
|
|
|
// vertical: 12.h, |
|
|
|
|
// ), |
|
|
|
|
contentPadding: EdgeInsets.symmetric( |
|
|
|
|
vertical: 14.h, |
|
|
|
|
), |
|
|
|
|
hintText: "输入城市名进行搜索", |
|
|
|
|
hintStyle: TextStyle( |
|
|
|
|
fontSize: 12.sp, |
|
|
|
@ -328,7 +275,7 @@ class _UnionSelectCity extends State<UnionSelectCity> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Widget sortList() { |
|
|
|
|
return ListView.builder( |
|
|
|
|
return areaList.length != 0 ?ListView.builder( |
|
|
|
|
padding: EdgeInsets.zero, |
|
|
|
|
itemCount: areaList.length, |
|
|
|
|
scrollDirection: Axis.vertical, |
|
|
|
@ -340,7 +287,15 @@ class _UnionSelectCity extends State<UnionSelectCity> {
|
|
|
|
|
child: sortItem(position), |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
):Padding(padding:EdgeInsets.only(top:12.h), |
|
|
|
|
child: Text( |
|
|
|
|
"抱歉,未找到相关位置,可尝试修改后重试", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF4D4D4D), |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
), |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Widget sortItem(int position) { |
|
|
|
@ -369,29 +324,31 @@ class _UnionSelectCity extends State<UnionSelectCity> {
|
|
|
|
|
padding: EdgeInsets.only( |
|
|
|
|
top: 8.h, |
|
|
|
|
), |
|
|
|
|
child: Column( |
|
|
|
|
children: (areaMap[areaList[position]] as List).map((e) { |
|
|
|
|
return globalRoamingItem(e); |
|
|
|
|
}).toList(), |
|
|
|
|
), |
|
|
|
|
child: mapWidget(position), |
|
|
|
|
) |
|
|
|
|
], |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Widget globalRoamingItem(data) { |
|
|
|
|
Widget mapWidget(position) { |
|
|
|
|
int mapIndex = 0; |
|
|
|
|
return Column( |
|
|
|
|
children: (areaMap[areaList[position]] as List).map((e) { |
|
|
|
|
mapIndex += 1; |
|
|
|
|
return globalRoamingItem( |
|
|
|
|
e, mapIndex == areaMap[areaList[position]].length); |
|
|
|
|
}).toList(), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Widget globalRoamingItem(data, isLast) { |
|
|
|
|
return GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: () { |
|
|
|
|
Navigator.of(context).pop(data["area"]); |
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
child: Column( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(left: 12.w), |
|
|
|
|
width: double.infinity, |
|
|
|
|
child: Text( |
|
|
|
|
data["area"], |
|
|
|
|
style: TextStyle( |
|
|
|
@ -400,15 +357,18 @@ class _UnionSelectCity extends State<UnionSelectCity> {
|
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Container( |
|
|
|
|
margin: EdgeInsets.symmetric(vertical: 16.h), |
|
|
|
|
width: double.infinity, |
|
|
|
|
height: 1.h, |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
border: isLast |
|
|
|
|
? null |
|
|
|
|
: Border( |
|
|
|
|
bottom: BorderSide( |
|
|
|
|
width: 1.w, |
|
|
|
|
color: Color(0xFFDCDCDC), |
|
|
|
|
) |
|
|
|
|
], |
|
|
|
|
style: BorderStyle.solid, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.only(top: 16.h, bottom: 16.h, left: 16.w), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|