From 3465ac6e980f1473e4f42ba3eaafc7815423efec Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 27 十一月 2021 17:10:45 +0800 Subject: [PATCH] 功能完善 --- lib/ui/main/location.dart | 163 ++++++++++++++++++++++++++++++------------------------ 1 files changed, 91 insertions(+), 72 deletions(-) diff --git a/lib/ui/main/location.dart b/lib/ui/main/location.dart index b5cd841..70670ea 100644 --- a/lib/ui/main/location.dart +++ b/lib/ui/main/location.dart @@ -12,8 +12,10 @@ import 'package:locations/model/map/location_user_model.dart'; import 'package:locations/model/user/user_info.dart'; import 'package:locations/ui/map/location_search.dart'; +import 'package:locations/ui/map/travel.dart'; import 'package:locations/ui/mine/add_location_person.dart'; import 'package:locations/ui/mine/login.dart'; +import 'package:locations/ui/sos/sos.dart'; import 'package:locations/ui/widget/button.dart'; import 'package:locations/ui/widget/capture.dart'; import 'package:locations/ui/widget/dialog.dart'; @@ -59,14 +61,12 @@ //鐢ㄦ埛marker BMFMarker? userMarker; String? portrait; - BaiduLocation? location; + SimpleLocation? location; BMFMapOptions mapOptions = BMFMapOptions( showMapScaleBar: false, mapType: BMFMapType.Standard, - center: Global.currentPosition != null - ? Global.currentPosition - : BMFCoordinate(39.917215, 116.380341), + center: Global.currentPosition ?? BMFCoordinate(39.917215, 116.380341), mapScaleBarPosition: BMFPoint(0, 200), zoomLevel: 12, mapPadding: BMFEdgeInsets(left: 30, top: 0, right: 30, bottom: 200)); @@ -97,36 +97,30 @@ return; } Map<String, dynamic>? result = - await LocationApiUtil.getInviteLocation(uid!); + await LocationApiUtil.getInviteLocation(uid!); if (result!["code"] == 0) { LocationUserModel model = LocationUserModel.fromJson(result["data"]); - showGeneralDialog( - context: context, - pageBuilder: (BuildContext buildContext, Animation<double> animation, - Animation<double> secondaryAnimation) { - return RequireLocationDialog(model.targetPhone!, () { - LocationApiUtil.rejectInviteLocation(uid, model.id!) - .then((value) { - if (value!["code"] == 0) { - Navigator.of(context).pop(); - } else { - ToastUtil.toast(value!["msg"]); - } - }); - }, () { - LocationApiUtil.agreeInviteLocation(uid, model.id!).then((value) { - if (value!["code"] == 0) { - Navigator.of(context).pop(); - } else { - ToastUtil.toast(value!["msg"]); - } - }); + DialogUtil.showDialog( + context, + RequireLocationDialog(model.targetPhone!, () { + LocationApiUtil.rejectInviteLocation(uid, model.id!).then((value) { + if (value!["code"] == 0) { + Navigator.of(context).pop(); + } else { + ToastUtil.toast(value!["msg"]); + } }); - }); + }, () { + LocationApiUtil.agreeInviteLocation(uid, model.id!).then((value) { + if (value!["code"] == 0) { + Navigator.of(context).pop(); + } else { + ToastUtil.toast(value!["msg"]); + } + }); + })); } } - - @override void dispose() { @@ -174,7 +168,7 @@ //鎺т欢闃村奖 List<BoxShadow> getViewShadow() { return [ - BoxShadow( + const BoxShadow( blurRadius: 6.5, spreadRadius: 1, color: Color(0x4D0E96FF), @@ -238,7 +232,7 @@ padding: const EdgeInsets.fromLTRB(0, 18, 0, 0), decoration: BoxDecoration( color: Colors.white, - borderRadius: BorderRadius.only( + borderRadius: const BorderRadius.only( topLeft: Radius.circular(10), topRight: Radius.circular(10)), boxShadow: getViewShadow()), child: Flex( @@ -270,7 +264,7 @@ //鎺т欢闃村奖 List<BoxShadow> getViewShadow() { return [ - BoxShadow( + const BoxShadow( blurRadius: 6.5, spreadRadius: 1, color: Color(0x4D0E96FF), @@ -294,7 +288,7 @@ UserInfo? user; - BaiduLocation? _location; + UserLocationInfo? _userLocationInfo; GlobalKey rootWidgetKey = GlobalKey(); @@ -314,9 +308,14 @@ if (state == LocationState.success) { BaiduLocation location = BaiduLocation.fromJson(map); setState(() { - _location = location; + _userLocationInfo = UserLocationInfo( + uid: user!.id, + location: SimpleLocation.fromBaiDuLocation(location), + updateTime: location.locTime, + locationCount: 1); }); - eventBus.fire(UserLocationInfoEventBus(_location, user)); + eventBus.fire( + UserLocationInfoEventBus(_userLocationInfo!.location, user)); } }); }); @@ -343,8 +342,6 @@ eventBusLogin.cancel(); } - - void _selectLocationUser() async { await _getLocationUsers(); @@ -353,21 +350,35 @@ return; } - var selectUserType = await showGeneralDialog( - context: context, - pageBuilder: (BuildContext buildContext, Animation<double> animation, - Animation<double> secondaryAnimation) => - ListViewDialog( - ListView.builder( - padding: EdgeInsets.zero, - itemCount: userList!.length, - itemBuilder: (BuildContext context, int index) { - return _getUserItem(userList![index], index); - }), - () { - Navigator.of(context).pop(); - }, - )); + var selectUser = await DialogUtil.showDialog( + context, + ListViewDialog( + ListView.builder( + padding: EdgeInsets.zero, + itemCount: userList!.length, + itemBuilder: (BuildContext context, int index) { + return _getUserItem(userList![index], index); + }), + () { + Navigator.of(context).pop(); + }, + )); + if (selectUser != null) { + setState(() { + user = (selectUser as LocationUserModel).userInfo; + }); + + //寮�濮嬭幏鍙栧畾浣� + UserLocationInfo? _userLocation = + await LocationApiUtil.getLocation(user!.id!.toString()); + if (_userLocation != null) { + print("鏇存柊鏃堕棿:${_userLocation.updateTime}"); + setState(() { + _userLocationInfo = _userLocation; + }); + eventBus.fire(UserLocationInfoEventBus(_userLocation.location, user)); + } + } } Future _getLocationUsers() async { @@ -375,6 +386,8 @@ if (uid == null) return; Map<String, dynamic>? result = await LocationApiUtil.getLocationUsers(uid, 1); + + print(result); if (result!["code"] == 0) { List<dynamic> list = result!["data"]["list"]; @@ -405,7 +418,7 @@ }, child: Container( alignment: Alignment.center, - padding: EdgeInsets.fromLTRB(13, 0, 13, 0), + padding: const EdgeInsets.fromLTRB(13, 0, 13, 0), height: 45, decoration: BoxDecoration( color: Colors.white, @@ -431,7 +444,8 @@ ))), InkWell( onTap: () { - print("sos"); + NavigatorUtil.navigateToNextPage( + context, SOSPage(title: ""), (data) {}); }, child: Container( width: 45, @@ -455,22 +469,22 @@ child: Stack( children: [ //浣嶇疆淇℃伅 - _location == null + _userLocationInfo == null ? Container() : getPositionInfoView(context), //涓汉淇℃伅 Container( height: 100, - margin: EdgeInsets.only(top: 10), - padding: EdgeInsets.only(left: 15, top: 8, right: 15), + margin: const EdgeInsets.only(top: 10), + padding: const EdgeInsets.only(left: 15, top: 8, right: 15), decoration: BoxDecoration( borderRadius: BorderRadius.only( bottomLeft: Radius.circular(locationInfoHidden ? 10 : 0), bottomRight: Radius.circular(locationInfoHidden ? 10 : 0), - topLeft: Radius.circular(10), - topRight: Radius.circular(10)), + topLeft: const Radius.circular(10), + topRight: const Radius.circular(10)), color: Colors.white, boxShadow: getViewShadow()), child: Stack( @@ -490,7 +504,7 @@ "assets/images/main/icon_location_change_person.png", width: 13, ), - Text( + const Text( " 鍒囨崲瀹炴椂瀹氫綅浜�", style: TextStyle( color: ColorConstant.theme, @@ -504,7 +518,7 @@ crossAxisAlignment: CrossAxisAlignment.center, children: [ user == null - ? Image( + ? const Image( image: AssetImage( "assets/images/mine/icon_mine_default_portrait.png"), height: 33, @@ -549,7 +563,7 @@ user!.nickName!, softWrap: false, overflow: TextOverflow.ellipsis, - style: TextStyle( + style: const TextStyle( color: Color(0xFFA0A0A0), fontSize: 18), ), @@ -558,7 +572,7 @@ ), Text( "ID:${user!.id!}", - style: TextStyle( + style: const TextStyle( color: Color(0xFFA0A0A0), fontSize: 12), ) @@ -580,7 +594,12 @@ width: 82, fontSize: 12, onClick: () { - print("鐢熸垚杞ㄨ抗"); + NavigatorUtil.navigateToNextPage( + context, + MyTravelPage( + uid: user!.id, + ), + (data) {}); }, ), Container( @@ -604,7 +623,7 @@ ), //鏇村 - _location == null + _userLocationInfo == null ? Container() : Positioned( left: MediaQuery.of(context).size.width / 2 - @@ -617,7 +636,7 @@ locationInfoHidden = !locationInfoHidden; }); }, - child: Container( + child: SizedBox( width: 70, height: 40, child: Stack( @@ -826,7 +845,7 @@ color: const Color(0xFFCACDD3), borderRadius: BorderRadius.circular(20)), child: Text( - _location!.locTime!, + _userLocationInfo!.updateTime!, style: const TextStyle( color: Colors.white, fontSize: 10), ), @@ -848,10 +867,10 @@ ), Expanded( child: Text( - _location!.address!, + _userLocationInfo!.location!.address!, softWrap: false, overflow: TextOverflow.ellipsis, - style: TextStyle( + style: const TextStyle( color: Color(0xFFBABABA), fontSize: 12), )) ], @@ -874,7 +893,7 @@ ), Expanded( child: Text( - "N ${_location!.latitude!}锛學 ${_location!.longitude!}", + "N ${_userLocationInfo!.location!.latitude}锛學 ${_userLocationInfo!.location!.longitude}", softWrap: false, overflow: TextOverflow.ellipsis, style: const TextStyle( @@ -891,8 +910,8 @@ crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( - "鏌ョ湅鍏ㄩ儴鍏�100娆″畾浣� ", - style: TextStyle( + "鏌ョ湅鍏ㄩ儴鍏�${_userLocationInfo!.locationCount}娆″畾浣� ", + style: const TextStyle( color: Color(0xFF9DAAB3), fontSize: 10), ), Image.asset( -- Gitblit v1.8.0