| | |
| | | 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/map.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/utils/location_util.dart'; |
| | | import 'package:locations/utils/map_util.dart'; |
| | | import 'package:locations/utils/pageutils.dart'; |
| | | import 'package:locations/utils/permission_util.dart'; |
| | | import 'package:locations/utils/string_util.dart'; |
| | | import 'package:locations/utils/ui_constant.dart'; |
| | | import 'package:locations/utils/ui_utils.dart'; |
| | | import 'package:locations/utils/user_util.dart'; |
| | | import 'package:path_provider/path_provider.dart'; |
| | | import 'package:permission_handler/permission_handler.dart'; |
| | | |
| | | typedef OnPositionHiidenChange = void Function(bool hidden); |
| | | |
| | |
| | | |
| | | @override |
| | | _LocationPageState createState() => _LocationPageState(); |
| | | |
| | | //获取定位邀请 |
| | | static void getLocationInvite(BuildContext context) async { |
| | | var uid = await UserUtil.getUid(); |
| | | if (uid == null) { |
| | | return; |
| | | } |
| | | Map<String, dynamic>? result = |
| | | await LocationApiUtil.getInviteLocation(uid); |
| | | if (result!["code"] == 0) { |
| | | LocationUserModel model = LocationUserModel.fromJson(result["data"]); |
| | | 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"]); |
| | | } |
| | | }); |
| | | })); |
| | | } |
| | | } |
| | | } |
| | | |
| | | class _LocationPageState extends State<LocationPage> |
| | |
| | | zoomLevel: 12, |
| | | mapPadding: BMFEdgeInsets(left: 30, top: 0, right: 30, bottom: 200)); |
| | | |
| | | //定位 |
| | | var eventBusLocation; |
| | | |
| | | //定位权限 |
| | | var eventBusLocationPermission; |
| | | |
| | | PermissionStatus? locationPermissionStatus; |
| | | |
| | | @override |
| | | void initState() { |
| | |
| | | drawMarker( |
| | | BMFCoordinate(event.location!.latitude!, event.location!.longitude!)); |
| | | }); |
| | | _getLocationInvite(); |
| | | |
| | | eventBusLocationPermission = |
| | | eventBus.on<UserLocationPermissionEventBus>().listen((event) { |
| | | setState(() { |
| | | locationPermissionStatus = event.status; |
| | | }); |
| | | }); |
| | | |
| | | Permission.locationAlways.status.then((value) { |
| | | setState(() { |
| | | locationPermissionStatus = value; |
| | | }); |
| | | }); |
| | | |
| | | LocationPage.getLocationInvite(context); |
| | | } |
| | | |
| | | void _getLocationInvite() async { |
| | | var uid = await UserUtil.getUid(); |
| | | if (uid == null) { |
| | | return; |
| | | } |
| | | Map<String, dynamic>? result = |
| | | await LocationApiUtil.getInviteLocation(uid!); |
| | | if (result!["code"] == 0) { |
| | | LocationUserModel model = LocationUserModel.fromJson(result["data"]); |
| | | 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() { |
| | | super.dispose(); |
| | | (eventBusLocation as StreamSubscription).cancel(); |
| | | (eventBusLocationPermission as StreamSubscription).cancel(); |
| | | } |
| | | |
| | | @override |
| | |
| | | height: 33, |
| | | width: 33, |
| | | ))), |
| | | Align( |
| | | alignment: Alignment.bottomCenter, |
| | | child: getAddLocationObjectView()), |
| | | |
| | | |
| | | locationPermissionStatus != null && |
| | | locationPermissionStatus != PermissionStatus.granted |
| | | ? Align( |
| | | alignment: Alignment.bottomCenter, |
| | | child: InkWell( |
| | | onTap: () { |
| | | PermissionUtil.openPermission( |
| | | Permission.locationAlways, |
| | | force: true) |
| | | .then((value) { |
| | | setState(() { |
| | | locationPermissionStatus = value; |
| | | }); |
| | | }); |
| | | }, |
| | | child: Container( |
| | | height: 38, |
| | | margin: const EdgeInsets.fromLTRB(10, 0, 10, 80), |
| | | padding: const EdgeInsets.fromLTRB(18, 0, 10, 0), |
| | | decoration: BoxDecoration( |
| | | color: const Color(0xFFFF5163), |
| | | borderRadius: BorderRadius.circular(10), |
| | | ), |
| | | child: Row( |
| | | children: [ |
| | | const Text( |
| | | "开启位置权限后软件才能正常运行", |
| | | style: TextStyle( |
| | | color: Colors.white, fontSize: 15), |
| | | ), |
| | | Expanded(child: Container()), |
| | | const Text( |
| | | "去开启", |
| | | style: TextStyle( |
| | | color: Colors.white, fontSize: 15), |
| | | ), |
| | | const SizedBox( |
| | | width: 7, |
| | | ), |
| | | Image.asset( |
| | | "assets/images/common/icon_location_permission_input.png", |
| | | width: 10, |
| | | ) |
| | | ], |
| | | ), |
| | | ))) |
| | | : Container(), |
| | | |
| | | //地图marker截图组件 |
| | | Positioned( |
| | |
| | | if (_mapController == null) { |
| | | return; |
| | | } |
| | | Directory? tempDir = await getExternalStorageDirectory(); |
| | | String tempPath = tempDir!.path; |
| | | File? file = |
| | | await _captureController.capturePng("$tempPath/location_person.png"); |
| | | |
| | | String base64Img = await _captureController.capturePng(); |
| | | if (userMarker == null) { |
| | | userMarker = |
| | | await MapUtil.addMarker(_mapController, location, file!.path); |
| | | userMarker = await MapUtil.addMarker(_mapController, location, base64Img); |
| | | } else { |
| | | userMarker!.updateIcon(file!.path); |
| | | userMarker!.updateIcon(base64Img); |
| | | userMarker!.updatePosition(location); |
| | | } |
| | | _mapController!.setCenterCoordinate(location, true); |
| | | } |
| | | |
| | | //添加想定位的人 |
| | | Widget getAddLocationObjectView() { |
| | | return InkWell( |
| | | onTap: () { |
| | | UserUtil.isLogin().then((value) { |
| | | if (!value) { |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, LoginPage(title: ""), (data) {}); |
| | | return; |
| | | } |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, AddLocationPersonPage(title: ""), (data) {}); |
| | | }); |
| | | }, |
| | | child: Container( |
| | | alignment: Alignment.topCenter, |
| | | height: 72, |
| | | margin: const EdgeInsets.fromLTRB(10, 0, 10, 0), |
| | | padding: const EdgeInsets.fromLTRB(0, 18, 0, 0), |
| | | decoration: BoxDecoration( |
| | | color: Colors.white, |
| | | borderRadius: const BorderRadius.only( |
| | | topLeft: Radius.circular(10), topRight: Radius.circular(10)), |
| | | boxShadow: getViewShadow()), |
| | | child: Flex( |
| | | direction: Axis.horizontal, |
| | | mainAxisAlignment: MainAxisAlignment.center, |
| | | crossAxisAlignment: CrossAxisAlignment.center, |
| | | children: [ |
| | | Image.asset( |
| | | "assets/images/common/icon_person.png", |
| | | height: 17, |
| | | ), |
| | | Container( |
| | | width: 11, |
| | | height: 1, |
| | | ), |
| | | const Text( |
| | | "添加想定位的对象", |
| | | style: TextStyle(color: ColorConstant.theme, fontSize: 15), |
| | | ) |
| | | ], |
| | | ), |
| | | )); |
| | | } |
| | | |
| | | @override |
| | | bool get wantKeepAlive => true; |
| | |
| | | BaiduLocation location = BaiduLocation.fromJson(map); |
| | | setState(() { |
| | | _userLocationInfo = UserLocationInfo( |
| | | uid: user!.id, |
| | | uid: user != null ? user!.id : null, |
| | | location: SimpleLocation.fromBaiDuLocation(location), |
| | | updateTime: location.locTime, |
| | | locationCount: 1); |
| | |
| | | }, |
| | | )); |
| | | if (selectUser != null) { |
| | | setState(() { |
| | | user = (selectUser as LocationUserModel).userInfo; |
| | | }); |
| | | _setSelectUserData(selectUser); |
| | | } |
| | | } |
| | | |
| | | //开始获取定位 |
| | | UserLocationInfo? _userLocation = |
| | | await LocationApiUtil.getLocation(user!.id!.toString()); |
| | | if (_userLocation != null) { |
| | | print("更新时间:${_userLocation.updateTime}"); |
| | | setState(() { |
| | | _userLocationInfo = _userLocation; |
| | | }); |
| | | eventBus.fire(UserLocationInfoEventBus(_userLocation.location, user)); |
| | | } |
| | | _setSelectUserData(LocationUserModel selectUser) async { |
| | | setState(() { |
| | | user = selectUser.userInfo; |
| | | }); |
| | | |
| | | //开始获取定位 |
| | | UserLocationInfo? _userLocation = |
| | | await LocationApiUtil.getLocation(user!.id!.toString()); |
| | | if (_userLocation != null) { |
| | | print("更新时间:${_userLocation.updateTime}"); |
| | | setState(() { |
| | | _userLocationInfo = _userLocation; |
| | | }); |
| | | eventBus.fire(UserLocationInfoEventBus(_userLocation.location, user)); |
| | | } |
| | | } |
| | | |
| | |
| | | print(result); |
| | | |
| | | if (result!["code"] == 0) { |
| | | List<dynamic> list = result!["data"]["list"]; |
| | | List<dynamic> list = result["data"]["list"]; |
| | | List<LocationUserModel> users = []; |
| | | list.forEach((element) { |
| | | users.add(LocationUserModel.fromJson(element)); |
| | | }); |
| | | userList = users; |
| | | } else { |
| | | ToastUtil.toast(result!["msg"]); |
| | | ToastUtil.toast(result["msg"]); |
| | | } |
| | | } |
| | | |
| | |
| | | ))), |
| | | InkWell( |
| | | onTap: () { |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, SOSPage(title: ""), (data) {}); |
| | | UserUtil.isLogin().then((value) { |
| | | if (value) { |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, SOSPage(title: ""), (data) {}); |
| | | } else { |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, LoginPage(title: ""), (data) {}); |
| | | } |
| | | }); |
| | | }, |
| | | child: Container( |
| | | width: 45, |
| | |
| | | fontSize: 12, |
| | | onClick: () { |
| | | print("实时共享"); |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, |
| | | MapPage( |
| | | "位置共享", |
| | | share: true, |
| | | uid: user!.id, |
| | | location: |
| | | _userLocationInfo != null |
| | | ? _userLocationInfo! |
| | | .location |
| | | : null, |
| | | ), |
| | | (data) {}); |
| | | }, |
| | | ), |
| | | ]) |
| | |
| | | ])))) |
| | | ], |
| | | )), |
| | | Expanded(child: |
| | | |
| | | Align( |
| | | alignment: Alignment.bottomCenter, |
| | | child: getAddLocationObjectView())), |
| | | ])); |
| | | } |
| | | |
| | | |
| | | //添加想定位的人 |
| | | Widget getAddLocationObjectView() { |
| | | return InkWell( |
| | | onTap: () { |
| | | UserUtil.isLogin().then((value) { |
| | | if (!value) { |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, LoginPage(title: ""), (data) {}); |
| | | return; |
| | | } |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, AddLocationPersonPage(title: ""), (data) { |
| | | |
| | | if(data!=null) { |
| | | _setSelectUserData(data); |
| | | } |
| | | }); |
| | | }); |
| | | }, |
| | | child: Container( |
| | | alignment: Alignment.topCenter, |
| | | height: 72, |
| | | // margin: const EdgeInsets.fromLTRB(10, 0, 10, 0), |
| | | padding: const EdgeInsets.fromLTRB(0, 18, 0, 0), |
| | | decoration: BoxDecoration( |
| | | color: Colors.white, |
| | | borderRadius: const BorderRadius.only( |
| | | topLeft: Radius.circular(10), topRight: Radius.circular(10)), |
| | | boxShadow: getViewShadow()), |
| | | child: Flex( |
| | | direction: Axis.horizontal, |
| | | mainAxisAlignment: MainAxisAlignment.center, |
| | | crossAxisAlignment: CrossAxisAlignment.center, |
| | | children: [ |
| | | Image.asset( |
| | | "assets/images/common/icon_person.png", |
| | | height: 17, |
| | | ), |
| | | Container( |
| | | width: 11, |
| | | height: 1, |
| | | ), |
| | | const Text( |
| | | "添加想定位的对象", |
| | | style: TextStyle(color: ColorConstant.theme, fontSize: 15), |
| | | ) |
| | | ], |
| | | ), |
| | | )); |
| | | } |
| | | |
| | | Widget _getStatus(LocationInviteStatus? status, LocationUserModel user) { |
| | |
| | | Container( |
| | | height: 5, |
| | | ), |
| | | Flex( |
| | | direction: Axis.horizontal, |
| | | mainAxisAlignment: MainAxisAlignment.center, |
| | | crossAxisAlignment: CrossAxisAlignment.center, |
| | | children: [ |
| | | Text( |
| | | "查看全部共${_userLocationInfo!.locationCount}次定位 ", |
| | | style: const TextStyle( |
| | | color: Color(0xFF9DAAB3), fontSize: 10), |
| | | ), |
| | | Image.asset( |
| | | "assets/images/main/icon_location_position_more.png", |
| | | height: 10, |
| | | ), |
| | | ], |
| | | ), |
| | | InkWell( |
| | | onTap: () { |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, |
| | | MyTravelPage(uid: _userLocationInfo!.uid), |
| | | (data) {}); |
| | | }, |
| | | child: Flex( |
| | | direction: Axis.horizontal, |
| | | mainAxisAlignment: MainAxisAlignment.center, |
| | | crossAxisAlignment: CrossAxisAlignment.center, |
| | | children: [ |
| | | Text( |
| | | "查看全部共${_userLocationInfo!.locationCount}次定位 ", |
| | | style: const TextStyle( |
| | | color: Color(0xFF9DAAB3), fontSize: 10), |
| | | ), |
| | | Image.asset( |
| | | "assets/images/main/icon_location_position_more.png", |
| | | height: 10, |
| | | ), |
| | | ], |
| | | )), |
| | | ], |
| | | ), |
| | | )))); |