Browse Source

联盟板块新ui更改完成;

dev
huixiang_app 1 year ago
parent
commit
b82d328bb2
  1. 2
      assets/map_style/chinese_cities.json
  2. 2
      lib/main.dart
  3. 78
      lib/retrofit/data/ip_data.dart
  4. 79
      lib/retrofit/retrofit_api.dart
  5. 20
      lib/retrofit/retrofit_api.g.dart
  6. 339
      lib/union/union_list.dart
  7. 864
      lib/union/union_page.dart
  8. 326
      lib/union/union_select_city.dart

2
assets/map_style/chinese_cities.json

@ -6,7 +6,7 @@
{"area": "广州"},
{"area": "成都"},
{"area": "杭州"},
{"area": "南京"},
{"area": "武汉"},
{"area": "重庆"}
],
"A": [

2
lib/main.dart

@ -442,5 +442,5 @@ Map<String, WidgetBuilder> routers = <String, WidgetBuilder>{
'/router/trading_card_page': (context, {arguments}) =>
TradingCardPage(),
'/router/union_select_city': (context, {arguments}) =>
UnionSelectCity(),
UnionSelectCity(arguments:arguments),
};

78
lib/retrofit/data/ip_data.dart

@ -0,0 +1,78 @@
/// code : 200
/// msg : "success"
/// ip : "27.17.85.129"
/// country : "中国"
/// province : "湖北"
/// city : "武汉市"
/// isp : "电信"
class IpData {
IpData({
num code,
String msg,
String ip,
String country,
String province,
String city,
String isp,}){
_code = code;
_msg = msg;
_ip = ip;
_country = country;
_province = province;
_city = city;
_isp = isp;
}
IpData.fromJson(dynamic json) {
_code = json['code'];
_msg = json['msg'];
_ip = json['ip'];
_country = json['country'];
_province = json['province'];
_city = json['city'];
_isp = json['isp'];
}
num _code;
String _msg;
String _ip;
String _country;
String _province;
String _city;
String _isp;
IpData copyWith({ num code,
String msg,
String ip,
String country,
String province,
String city,
String isp,
}) => IpData( code: code ?? _code,
msg: msg ?? _msg,
ip: ip ?? _ip,
country: country ?? _country,
province: province ?? _province,
city: city ?? _city,
isp: isp ?? _isp,
);
num get code => _code;
String get msg => _msg;
String get ip => _ip;
String get country => _country;
String get province => _province;
String get city => _city;
String get isp => _isp;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['code'] = _code;
map['msg'] = _msg;
map['ip'] = _ip;
map['country'] = _country;
map['province'] = _province;
map['city'] = _city;
map['isp'] = _isp;
return map;
}
}

79
lib/retrofit/retrofit_api.dart

@ -41,6 +41,7 @@ import 'data/headlines_list.dart';
import 'data/headlines_list_details.dart';
import 'data/home_rank.dart';
import 'data/invitation_list.dart';
import 'data/ip_data.dart';
import 'data/logistics.dart';
import 'data/member_Infor.dart';
import 'data/member_comment_list.dart';
@ -66,9 +67,17 @@ import 'data/wx_pay.dart';
part 'retrofit_api.g.dart';
const localBaseUrl = "http://192.168.10.15:8766/app/";///
const localBaseUrl = "http://platform-api.test.yixinhuixiang.com/app/";
///
// const localBaseUrl = "http://platform.test.api.lotus-wallet.com/app/";///
const serviceBaseUrl = "https://pos.platform.lotus-wallet.com/app/";///线
const serviceBaseUrl = "https://pos.platform.lotus-wallet.com/app/";
///线
const ipBaseUrl = "https://api.ooomn.com";
///ip
@RestApi(baseUrl: localBaseUrl)
abstract class ApiService {
@ -78,6 +87,7 @@ abstract class ApiService {
BuildContext context,
String token,
bool showLoading = false,
bool isIp = false,
bool pay = true,
}) {
Map<String, dynamic> headers =
@ -85,6 +95,7 @@ abstract class ApiService {
if (pay) {
headers["Environment"] = "app";
}
if (isIp) baseUrl = ipBaseUrl;
dio.options = BaseOptions(
connectTimeout: 60000,
receiveTimeout: 60000,
@ -113,14 +124,16 @@ abstract class ApiService {
EasyLoading.dismiss();
}
debugPrint("code = ${response.statusCode}");
if (response.request.path != "/creditGoods/list")
p(jsonEncode(response.data));
// debugPrint(jsonEncode(response.data), wrapWidth: response.data.toString().length * 10);
Map map = response.data;
if (map["code"] != 0) {
EasyLoading.dismiss();
}
// if (map["code"] != 0) {
// EasyLoading.dismiss();
// }
if (map["code"] == 40005 || map["code"] == 40001) {
if (!LoginTipsDialog().isShow) {
print("show: ${LoginTipsDialog().isShow}");
@ -166,11 +179,12 @@ abstract class ApiService {
///
@POST("/file/upload")
@MultiPart()
Future<BaseData<UploadResult>> upload(
@Part(name: "file") File data, @Part(name: "folderId") int folderId,bool isVideo);
Future<BaseData<UploadResult>> upload(@Part(name: "file") File data,
@Part(name: "folderId") int folderId, bool isVideo);
///
@GET("https://restapi.amap.com/v3/place/around?key=542b46afa8e4b88fe1eb3c4d0ba0872f&location={lat},{lng}&keywords={keywords}&offset={size}&page={page}&extensions=all")
@GET(
"https://restapi.amap.com/v3/place/around?key=542b46afa8e4b88fe1eb3c4d0ba0872f&location={lat},{lng}&keywords={keywords}&offset={size}&page={page}&extensions=all")
Future<dynamic> searchPoi(@Path("lat") String lat, @Path("lng") String lng,
@Path("keywords") String keywords, int size, int page);
@ -184,7 +198,8 @@ abstract class ApiService {
///
@GET("/auth/sendVerify/{areaCode}/{mobile}")
Future<BaseData> sendVerify(@Path("areaCode") String areaCode, @Path("mobile") String mobile);
Future<BaseData> sendVerify(
@Path("areaCode") String areaCode, @Path("mobile") String mobile);
///
@POST("/creditGoods/list")
@ -298,11 +313,13 @@ abstract class ApiService {
///
@POST("/information/list")
Future<BaseData<PageInfo<Article>>> queryArticle(@Body() Map<String, dynamic> param);
Future<BaseData<PageInfo<Article>>> queryArticle(
@Body() Map<String, dynamic> param);
///banner查询
@POST("/banner/page")
Future<BaseData<PageInfo<BannerData>>> queryBanner(@Body() Map<String, dynamic> param);
Future<BaseData<PageInfo<BannerData>>> queryBanner(
@Body() Map<String, dynamic> param);
///
@GET("/home/brand")
@ -404,11 +421,13 @@ abstract class ApiService {
///
@POST("/information/trend-list")
Future<BaseData<PageInfo<ComunityComment>>> trendList(@Body() Map<String, dynamic> map);
Future<BaseData<PageInfo<ComunityComment>>> trendList(
@Body() Map<String, dynamic> map);
/// /
@POST("/member/follow/list")
Future<BaseData<PageInfo<ListData>>> followList(@Body() Map<String, dynamic> map);
Future<BaseData<PageInfo<ListData>>> followList(
@Body() Map<String, dynamic> map);
////
@PUT("/member/follow/{followId}")
@ -428,11 +447,13 @@ abstract class ApiService {
///
@GET("/course/catalogList/{courseId}")
Future<BaseData<List<Chapter>>> catalogList(@Path("courseId") String courseId);
Future<BaseData<List<Chapter>>> catalogList(
@Path("courseId") String courseId);
///
@POST("/course/list")
Future<BaseData<PageInfo<CourseList>>> courseList(@Body() Map<String, dynamic> map);
Future<BaseData<PageInfo<CourseList>>> courseList(
@Body() Map<String, dynamic> map);
///
@GET("/course/collectList")
@ -440,7 +461,8 @@ abstract class ApiService {
///
@GET("/course/collect/{collectId}")
Future<BaseData<List<CourseList>>> collect(@Path("collectId") String collectId);
Future<BaseData<List<CourseList>>> collect(
@Path("collectId") String collectId);
///
@GET("/course/{id}")
@ -452,11 +474,14 @@ abstract class ApiService {
/// APP查询所有成就徽章
@POST("/app-memberAchievement/findBadges")
Future<BaseData<List<VipBadgesList>>> findBadges(@Body() Map<String, dynamic> map);
Future<BaseData<List<VipBadgesList>>> findBadges(
@Body() Map<String, dynamic> map);
///
@GET("/app-memberAchievement/getAchievementDetail?achievementCategoryId={achievementCategoryId}")
Future<BaseData<List<AchievementDetailList>>> getAchievementDetail(@Path("achievementCategoryId") String achievementCategoryId);
@GET(
"/app-memberAchievement/getAchievementDetail?achievementCategoryId={achievementCategoryId}")
Future<BaseData<List<AchievementDetailList>>> getAchievementDetail(
@Path("achievementCategoryId") String achievementCategoryId);
///
@GET("/member/benefitList")
@ -480,7 +505,8 @@ abstract class ApiService {
///
@GET("/creditOrder/getAppShippingTrace?orderId={orderId}")
Future<BaseData<Logistics>> getAppShippingTrace(@Path("orderId") String orderId);
Future<BaseData<Logistics>> getAppShippingTrace(
@Path("orderId") String orderId);
///
@POST("/member/rankBuy")
@ -492,11 +518,13 @@ abstract class ApiService {
///
@GET("/information/category/{id}")
Future<BaseData<HeadlinesListDetails>> headlinesDetails(@Path("id") String id);
Future<BaseData<HeadlinesListDetails>> headlinesDetails(
@Path("id") String id);
///
@POST("/member/inviteMemberList")
Future<BaseData<PageInfo<InvitationList>>> inviteMemberList(@Body() Map<String, dynamic> map);
Future<BaseData<PageInfo<InvitationList>>> inviteMemberList(
@Body() Map<String, dynamic> map);
///
@GET("/coupon/wiped/{memberCouponId}")
@ -564,5 +592,10 @@ abstract class ApiService {
///
@GET("/store/storeListByCreditId/{creditGoodsId}")
Future<BaseData<List<Store>>> storeListByCreditId(@Path("creditGoodsId") String creditGoodsId);
Future<BaseData<List<Store>>> storeListByCreditId(
@Path("creditGoodsId") String creditGoodsId);
///APP门店推广渠道
@GET("/api/ip")
Future<IpData> getIpInfo();
}

20
lib/retrofit/retrofit_api.g.dart

@ -2109,6 +2109,26 @@ class _ApiService implements ApiService {
return value;
}
@override
Future<IpData> getIpInfo() async {
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
final _result = await _dio.request<Map<String, dynamic>>(
'/api/ip',
queryParameters: queryParameters,
options: RequestOptions(
method: 'GET',
headers: <String, dynamic>{},
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = IpData.fromJson(
_result.data,
);
return value;
}
@override
Future<BaseData<dynamic>> orderVip(param) async {
ArgumentError.checkNotNull(param, 'param');

339
lib/union/union_list.dart

@ -1,28 +1,32 @@
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/store.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/border_text.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/request_permission.dart';
import 'package:huixiang/view_widget/round_button.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:shimmer/shimmer.dart';
import '../retrofit/data/base_data.dart';
import '../retrofit/retrofit_api.dart';
import '../utils/flutter_utils.dart';
import '../view_widget/classic_header.dart';
import '../view_widget/no_data_view.dart';
class UnionList extends StatefulWidget {
final RefreshController refreshController;
final List<Store> storeList;
final Function onRefresh;
final Function queryStore;
UnionList(this.refreshController,this.storeList,this.onRefresh,this.queryStore);
final String serviceType;
final BMFCoordinate latLng;
final String searchKey;
final String city;
UnionList(Key key, this.serviceType, this.latLng, this.searchKey, this.city)
: super(key: key);
@override
State<StatefulWidget> createState() {
@ -30,89 +34,105 @@ class UnionList extends StatefulWidget {
}
}
class _UnionList extends State<UnionList> {
final TextEditingController editingController = TextEditingController();
class _UnionList extends State<UnionList> with AutomaticKeepAliveClientMixin {
ApiService apiService;
List<Store> storeList;
final RefreshController _refreshController = RefreshController();
@override
bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
queryStore();
}
queryStore() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
);
}
BaseData<List<Store>> baseData = await apiService.queryStore({
"city": widget.city ?? "",
// "district": district,
// "province": province,
"latitude": (widget.latLng?.latitude ?? "").toString(),
"longitude": (widget.latLng?.longitude ?? "").toString(),
if (widget.searchKey != "") "searchKey": widget.searchKey,
"serviceType": widget.serviceType,
"exchange": false,
}).catchError((error) {
SmartDialog.showToast(AppUtils.dioErrorTypeToString(error.type),
alignment: Alignment.center);
});
if (baseData != null && baseData.isSuccess) {
storeList = baseData.data;
}
_refreshController.refreshCompleted();
EasyLoading.dismiss();
setState(() {});
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// buildSearchItem(),
Container(
height: MediaQuery.of(context).size.height -
103.h -
MediaQuery.of(context).padding.top,
child: SmartRefresher(
controller: widget.refreshController,
enablePullUp: false,
return SmartRefresher(
controller: _refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(color: Colors.white,),
physics: BouncingScrollPhysics(),
header: MyHeader(),
onRefresh: widget.onRefresh,
child: (widget.storeList == null || widget.storeList.length == 0)
onRefresh: queryStore,
child: (storeList == null || storeList.length == 0)
? NoDataView(
src:"assets/image/di_zhi.webp",
src: "assets/image/di_zhi.webp",
isShowBtn: false,
text: "暂无店铺列表~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h),
):ListView.builder(
itemCount:widget.storeList == null ? 0 : widget.storeList.length,
)
: ListView.builder(
itemCount: storeList.length,
padding: EdgeInsets.only(
top: 8.h,
bottom: 100.h, /* + (375.h - 88.h) + 4.h*/
bottom: 100.h,
),
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, position) {
return InkWell(
onTap: () {
// if (widget.storeList[position].posType.code == "NORMALSTORE") {
// showDeleteDialog();
// }
// else
// if ( widget.storeList[position].storeName == "一心回乡商城") {
// Navigator.of(context).pushNamed(
// '/router/shopping_mall_home',
// arguments: {
// "type": 0,
// "id": widget.storeList[position].id,
// "tenant": widget.storeList[position].tenantCode,
// "storeName": widget.storeList[position].storeName
// },
// );
// }
// else
{
Navigator.of(context).pushNamed(
'/router/store_order',
arguments: {
"id": widget.storeList[position].id,
"tenant": widget.storeList[position].tenantCode,
"storeName": widget.storeList[position].storeName,
"distance":widget.storeList[position].distance
"id": storeList[position].id,
"tenant": storeList[position].tenantCode,
"storeName": storeList[position].storeName,
"distance": storeList[position].distance
},
);
}
},
child:
buildStoreItem(widget.storeList[position], position),
child: buildStoreItem(storeList[position], position),
);
})),
)
],
},
),
);
}
Widget sm(){
Widget sm() {
return Container(
margin:EdgeInsets.symmetric(horizontal: 14.w,vertical: 8.h),
margin: EdgeInsets.symmetric(horizontal: 14.w, vertical: 8.h),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(6),
),
height: 223.h,
child:Column(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Shimmer.fromColors(
@ -124,7 +144,8 @@ class _UnionList extends State<UnionList> {
height: 140.h,
),
),
Padding(padding: EdgeInsets.only(left: 6.w,bottom: 5.h,top: 12.h),
Padding(
padding: EdgeInsets.only(left: 6.w, bottom: 5.h, top: 12.h),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
@ -136,7 +157,12 @@ class _UnionList extends State<UnionList> {
width: 108.w,
height: 20.h,
),
),),Padding(padding: EdgeInsets.only(left: 6.w,),
),
),
Padding(
padding: EdgeInsets.only(
left: 6.w,
),
child: Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
@ -148,64 +174,10 @@ class _UnionList extends State<UnionList> {
width: 260.w,
height: 20.h,
),
),),
],
),
);
}
Widget buildSearchItem() {
return Container(
height: 36.h,
margin: EdgeInsets.fromLTRB(6.w, 0, 14.w, 0),
padding: EdgeInsets.fromLTRB(0, 6.h, 0, 6.h),
decoration: BoxDecoration(
color: Color(0xFFF5FAF7),
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
),
],
),
child: TextField(
textInputAction: TextInputAction.search,
onEditingComplete: () {
FocusScope.of(context).requestFocus(FocusNode());
widget.queryStore(editingController.text);
},
controller: editingController,
cursorHeight: 25.h,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(
vertical: 12.h,
),
prefixIcon:InkWell(
onTap: () {
widget.queryStore(editingController.text);
},
child: Icon(
Icons.search,
size: 24,
color: Colors.black,
),
),
suffixIcon: InkWell(
onTap: () {
editingController.clear();
},
child: Icon(
Icons.close,
size: 19,
color: Colors.grey,
),
),
border: InputBorder.none,
),
),
);
}
@ -293,7 +265,8 @@ class _UnionList extends State<UnionList> {
SizedBox(
height: 5.h,
),
Expanded(child: Text(
Expanded(
child: Text(
"${S.of(context).dizhi}:${store.address}",
maxLines: 2,
overflow: TextOverflow.ellipsis,
@ -302,10 +275,11 @@ class _UnionList extends State<UnionList> {
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),)
),
)
],
)),
if(store.distance != null)
if (store.distance != null)
Container(
width: 59.w,
height: 18.h,
@ -322,7 +296,8 @@ class _UnionList extends State<UnionList> {
((store.distance ?? 0) / 1000 * 100).toInt() /
100.0)
: S.of(context).mi(
((store.distance ?? 0) * 100).toInt() / 100.0),
((store.distance ?? 0) * 100).toInt() /
100.0),
style: TextStyle(
color: Color(0xFFFFFFFF),
fontSize: 10.sp,
@ -339,130 +314,4 @@ class _UnionList extends State<UnionList> {
),
);
}
///
showDeleteDialog() {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Container(
width: MediaQuery.of(context).size.width - 84.w,
height: 130.h,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"您即将进行扫码点餐",
style: TextStyle(
fontSize: 17.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(
height: 30.h,
),
Row(
children: [
Expanded(
child: InkWell(
child: BorderText(
text: "取消",
textColor: Color(0xFF32A060),
fontSize: 16.sp,
fontWeight: FontWeight.bold,
borderColor: Color(0xFF32A060),
radius: 4,
padding: EdgeInsets.all(12),
borderWidth: 1,
),
onTap: () {
Navigator.of(context).pop();
},
),
flex: 1,
),
SizedBox(
width: 16.w,
),
Expanded(
child: InkWell(
child: RoundButton(
text: "确定",
textColor: Colors.white,
radius: 4,
padding: EdgeInsets.all(12),
backgroup: Color(0xFF32A060),
fontSize: 16.sp,
fontWeight: FontWeight.bold,
),
onTap: () {
toScan();
Navigator.of(context).pop();
},
),
flex: 1,
),
],
)
],
),
),
);
},
);
}
///
toScan() async {
if (await Permission.camera.isPermanentlyDenied) {
showCupertinoDialog(
context: context,
builder: (context) {
return RequestPermission(
"assets/image/icon_camera_permission_tips.webp",
S.of(context).ninxiangjiquanxianweikaiqi,
S.of(context).weilekaipaizhaoxuanzhetouxiang,
S.of(context).kaiqiquanxian,
(result) async {
if (result) {
await openAppSettings();
}
},
heightRatioWithWidth: 0.82,
);
});
} else if (await Permission.camera.isGranted) {
// http://pos.app.gznl.top/placeorder/?tableId=1315903669597634560&tenantCode=1166&shopId=1300372027722432512
//
// http://miniscan.lotus-wallet.com/placeorder?tenant_code=1194&table_id=1669609340031467520&store_id=1637659387134738432
var result = await Navigator.of(context).pushNamed('/router/qr_scan');
// String result = await scanner.scan();
Uri uri = Uri.parse(result);
String tableId = uri.queryParameters["tableId"] ?? uri.queryParameters["table_id"];
String tenantCode = uri.queryParameters["tenantCode"] ?? uri.queryParameters["tenant_code"];
String shopId = uri.queryParameters["shopId"] ?? uri.queryParameters["store_id"];
if (tableId != null &&
tableId != "" &&
tenantCode != null &&
tenantCode != "" &&
shopId != null &&
shopId != "") {
Navigator.of(context).pushNamed(
'/router/store_order',
arguments: {
"id": shopId,
"tenant": tenantCode,
"storeName": "",
"tableId": int.tryParse(tableId),
},
);
}
} else {
await Permission.camera.request();
}
}
}

864
lib/union/union_page.dart

File diff suppressed because it is too large Load Diff

326
lib/union/union_select_city.dart

@ -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(
@ -60,8 +99,8 @@ class _UnionSelectCity extends State<UnionSelectCity> {
onTap: () {
Navigator.of(context).pop();
},
child:Container(
padding: EdgeInsets.only(right:21.w),
child: Container(
padding: EdgeInsets.only(right: 21.w),
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
@ -70,207 +109,113 @@ class _UnionSelectCity extends State<UnionSelectCity> {
Expanded(child: searchCityItem())
],
),
Padding(padding:EdgeInsets.only(top: 16.h,bottom: 24.h),
child:Row(
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,
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,
),
)
)),
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,
),
)
)),
),)
],
),),
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("重庆");},
onTap: () {
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,
@ -315,7 +262,7 @@ class _UnionSelectCity extends State<UnionSelectCity> {
),
prefixIcon: InkWell(
onTap: () {},
child:Image.asset(
child: Image.asset(
"assets/image/icon_search.webp",
width: 16,
height: 16,
@ -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),
),
);
}

Loading…
Cancel
Save