From b6c99666cca668f8683624eb91badfa4c0fce6ef Mon Sep 17 00:00:00 2001 From: wurong <953969641@qq.com> Date: Sat, 2 Sep 2023 15:28:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 1 - lib/union/location_map_page.dart | 1041 +++++++++++++++------------- lib/union/union_page.dart | 249 ++++--- lib/utils/location.dart | 217 ++++-- lib/view_widget/location_tips.dart | 120 ++++ 5 files changed, 965 insertions(+), 663 deletions(-) create mode 100644 lib/view_widget/location_tips.dart diff --git a/lib/main.dart b/lib/main.dart index 44461e0b..0b9440db 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -73,7 +73,6 @@ import 'package:huixiang/settlement/settlement.dart'; import 'package:huixiang/store/store_view/product_meals_sku.dart'; import 'package:huixiang/test_page.dart'; import 'package:huixiang/union/location_map_page.dart'; -import 'package:huixiang/union/location_map_pages.dart'; import 'package:huixiang/union/union_select_city.dart'; import 'package:huixiang/utils/ImgCachePath.dart'; import 'package:huixiang/vip/user_vip_service_page.dart'; diff --git a/lib/union/location_map_page.dart b/lib/union/location_map_page.dart index 92bd5339..1ae4158a 100644 --- a/lib/union/location_map_page.dart +++ b/lib/union/location_map_page.dart @@ -14,10 +14,12 @@ import 'package:huixiang/utils/location.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:permission_handler/permission_handler.dart'; +import 'package:url_launcher/url_launcher.dart'; import '../generated/l10n.dart'; import '../retrofit/data/store_info.dart'; import '../view_widget/custom_image.dart'; +import '../view_widget/location_tips.dart'; import '../view_widget/round_button.dart'; class LocationMap extends StatefulWidget { @@ -31,7 +33,7 @@ class LocationMap extends StatefulWidget { } } -class _LocationMap extends State { +class _LocationMap extends State with WidgetsBindingObserver { StoreInfo storeInfo; int navigationState = 0; double distance; @@ -42,10 +44,12 @@ class _LocationMap extends State { String hours; String minutes; String polylineId; + bool _isShowLocalTips = false; @override void initState() { super.initState(); + WidgetsBinding.instance.addObserver(this); storeInfo = widget.arguments["storeInfo"]; distance = widget.arguments["distance"]; getLocation(); @@ -58,31 +62,33 @@ class _LocationMap extends State { Location.getInstance().stopLocation(); }); powerFlag = await Location.getInstance().startLocation(context, - (BaiduLocation result) { - if (result != null && - result.latitude != null && - result.longitude != null) { - print("location: $result"); - myLatLng = BMFCoordinate(result.latitude, result.longitude); - myAddress = result.locationDetail; - myCity = result.city; - if(distance == null) - calculate(); - AppUtils.coordConvert(myLatLng).then((value) { - this.myLatLng = value; - locationShow(); - }); - Location.getInstance().stopLocation(); - } + (BaiduLocation result) { + if (result != null && + result.latitude != null && + result.longitude != null) { + print("location: $result"); + myLatLng = BMFCoordinate(result.latitude, result.longitude); + myAddress = result.locationDetail; + myCity = result.city; + if (distance == null) calculate(); + AppUtils.coordConvert(myLatLng).then((value) { + this.myLatLng = value; + locationShow(); }); + Location.getInstance().stopLocation(); + } + }); } finally { if (!powerFlag) { if (await Permission.locationWhenInUse.status.isGranted) { getLocation(); } else { - SmartDialog.showToast("您定位服务未开启,请前往系统设置中开启定位服务", - alignment: Alignment.center); + _isShowLocalTips = true; } + // else { + // SmartDialog.showToast("您定位服务未开启,请前往系统设置中开启定位服务", + // alignment: Alignment.center); + // } } } } @@ -92,7 +98,8 @@ class _LocationMap extends State { double.tryParse(storeInfo.latitude), double.tryParse(storeInfo.longitude), ); - distance = double.tryParse(await AppUtils.calculateDistance(bmfCoordinate, myLatLng,isMi:true)); + distance = double.tryParse( + await AppUtils.calculateDistance(bmfCoordinate, myLatLng, isMi: true)); } locationShow() { @@ -114,8 +121,26 @@ class _LocationMap extends State { @override void dispose() { - super.dispose(); + WidgetsBinding.instance.removeObserver(this); Location.getInstance().stopLocation(); + super.dispose(); + } + + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + if (state == AppLifecycleState.resumed) { + // 处理应用程序切换回前台的逻辑 + permissionSettings(); + } else if (state == AppLifecycleState.paused) { + // 处理应用程序切换到后台的逻辑 + } + } + + void permissionSettings() async { + if (await Permission.location.isGranted) { + _isShowLocalTips = false; + getLocation(); + } } @override @@ -130,12 +155,14 @@ class _LocationMap extends State { // ), body: Stack( children: [ - Column( + Stack( children: [ - Expanded( - child: Container( - //BMFMapWidget 组件会自动默认沾满全屏,并且挡住所有遮盖物 ,BMFTextureMapWidget不会强制遮盖其他控件。 - child: BMFTextureMapWidget( + Column( + children: [ + Expanded( + child: Container( + //BMFMapWidget 组件会自动默认沾满全屏,并且挡住所有遮盖物 ,BMFTextureMapWidget不会强制遮盖其他控件。 + child: BMFTextureMapWidget( mapOptions: BMFMapOptions( center: BMFCoordinate( double.tryParse(widget.arguments["lat"]), @@ -148,208 +175,228 @@ class _LocationMap extends State { ), onBMFMapCreated: onMapCreated, )), - flex: 3, - ), - navigationState == 0 - ? Container( - height: 253.h, - padding: - EdgeInsets.only(top: 16.h, left: 16.w, right: 28.w), - decoration: BoxDecoration( - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Color(0x08213303), - offset: Offset(0, 2), - blurRadius: 4, - spreadRadius: 0, - ), - ], - borderRadius: BorderRadius.vertical( - top: Radius.circular(8), + flex: 3, ), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Row( - children: [ - Expanded( - child: Column( - children: [ - Text( - storeInfo?.storeName ?? "", - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 20.sp, - color: Color(0xFF0D0D0D), - fontWeight: MyFontWeight.medium, - ), - ), - Row( + navigationState == 0 + ? Container( + height: 253.h, + padding: EdgeInsets.only( + top: 16.h, left: 16.w, right: 28.w), + decoration: BoxDecoration( + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Color(0x08213303), + offset: Offset(0, 2), + blurRadius: 4, + spreadRadius: 0, + ), + ], + borderRadius: BorderRadius.vertical( + top: Radius.circular(8), + ), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Row( children: [ - Text( - S.of(context).ren( - storeInfo != null - ? storeInfo - .perCapitaConsumption - : "", - ), - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Color(0xFF4D4D4D), + Expanded( + child: Column( + children: [ + Text( + storeInfo?.storeName ?? "", + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 20.sp, + color: Color(0xFF0D0D0D), + fontWeight: MyFontWeight.medium, + ), + ), + Row( + children: [ + Text( + S.of(context).ren( + storeInfo != null + ? storeInfo + .perCapitaConsumption + : "", + ), + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 12.sp, + fontWeight: + MyFontWeight.regular, + color: Color(0xFF4D4D4D), + ), + ), + SizedBox( + width: 20.w, + ), + ]..addAll(itemServer( + storeInfo != null + ? storeInfo.businessService + : "")), + ), + Text( + S.of(context).yingyeshijian(storeInfo == + null + ? "" + : (storeInfo.openStartTime == + null && + storeInfo.openEndTime == + null) + ? S.of(context).quantian + : "${storeInfo.openStartTime.substring(0, storeInfo.openStartTime.lastIndexOf(":"))} " + "- ${storeInfo.openEndTime.substring(0, storeInfo.openEndTime.lastIndexOf(":"))}"), + style: TextStyle( + color: Color(0xFF4D4D4D), + fontWeight: MyFontWeight.medium, + fontSize: 12.sp, + ), + ), + ], + mainAxisAlignment: + MainAxisAlignment.spaceAround, + crossAxisAlignment: + CrossAxisAlignment.start, ), ), - SizedBox( - width: 20.w, + MImage( + storeInfo != null ? storeInfo.logo : "", + width: 72.h, + height: 72.h, + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.webp", + fadeSrc: "assets/image/default_1.webp", ), - ]..addAll(itemServer(storeInfo != null - ? storeInfo.businessService - : "")), + ], ), - Text( - S.of(context).yingyeshijian(storeInfo == - null - ? "" - : (storeInfo.openStartTime == - null && - storeInfo.openEndTime == - null) - ? S.of(context).quantian - : "${storeInfo.openStartTime.substring(0, storeInfo.openStartTime.lastIndexOf(":"))} " - "- ${storeInfo.openEndTime.substring(0, storeInfo.openEndTime.lastIndexOf(":"))}"), + ), + Padding( + padding: EdgeInsets.only(bottom: 32.h), + child: Text( + "${storeInfo != null ? storeInfo.address : ""}", + maxLines: 2, + textAlign: TextAlign.justify, style: TextStyle( - color: Color(0xFF4D4D4D), - fontWeight: MyFontWeight.medium, + color: Color(0xFF353535), + fontWeight: MyFontWeight.regular, fontSize: 12.sp, ), ), - ], - mainAxisAlignment: - MainAxisAlignment.spaceAround, - crossAxisAlignment: - CrossAxisAlignment.start, - ), - ), - MImage( - storeInfo != null ? storeInfo.logo : "", - width: 72.h, - height: 72.h, - fit: BoxFit.cover, - errorSrc: "assets/image/default_1.webp", - fadeSrc: "assets/image/default_1.webp", + ), + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + if (myCity == null) { + // onOpenBaiduMap(); + SmartDialog.showToast("您定位服务未开启,请前往系统设置中开启定位服务", + alignment: Alignment.center); + } else { + navigationState = 1; + if ((distance ?? 0) < 500) + navigationType = 1; + else if ((distance ?? 0) < 1500) + navigationType = 2; + else + navigationType = 4; + navigationPosition(); + } + }, + child: Container( + alignment: Alignment.center, + width: double.infinity, + padding: EdgeInsets.symmetric(vertical: 10.h), + margin: EdgeInsets.only(bottom: 30.h), + decoration: BoxDecoration( + color: Color(0xFF32A060), + borderRadius: BorderRadius.circular(23), + ), + child: Text( + "到这去", + style: TextStyle( + fontSize: 20.sp, + color: Colors.white, + fontWeight: MyFontWeight.medium, + ), + ), + ), + ) + ], ), - ], - ), - ), - Padding( - padding: EdgeInsets.only(bottom: 32.h), - child: Text( - "${storeInfo != null ? storeInfo.address : ""}", - maxLines: 2, - textAlign: TextAlign.justify, - style: TextStyle( - color: Color(0xFF353535), - fontWeight: MyFontWeight.regular, - fontSize: 12.sp, - ), - ), - ), - GestureDetector( + ) + : navigationDistance(), + ], + ), + navigationState == 0 + ? GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { - if (myCity == null) { - getLocation(); - } else { - navigationState = 1; - if ((distance ?? 0) < 500) - navigationType = 1; - else if ((distance ?? 0) < 1500) - navigationType = 2; - else navigationType = 4; - navigationPosition(); - } + Navigator.of(context).pop(); }, child: Container( - alignment: Alignment.center, - width: double.infinity, - padding: EdgeInsets.symmetric(vertical: 10.h), - margin: EdgeInsets.only(bottom: 30.h), + height: 56.h, + margin: EdgeInsets.only( + top: MediaQuery.of(context).padding.top + 16.h, + left: 14.w, + right: 14.w), + padding: EdgeInsets.only(left: 12.w, right: 21.w), decoration: BoxDecoration( - color: Color(0xFF32A060), - borderRadius: BorderRadius.circular(23), + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Color(0x08213303), + offset: Offset(0, 2), + blurRadius: 4, + spreadRadius: 0, + ), + ], + borderRadius: BorderRadius.circular(6), ), - child: Text( - "到这去", - style: TextStyle( - fontSize: 20.sp, - color: Colors.white, - fontWeight: MyFontWeight.medium, - ), + child: Row( + children: [ + Icon( + Icons.arrow_back_ios, + color: Color(0xFF353535), + size: 24, + ), + Expanded( + child: Text( + storeInfo?.storeName ?? "", + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Color(0xFF0D0D0D), + fontSize: 18.sp, + fontWeight: MyFontWeight.regular, + ), + )) + ], ), ), ) - ], - ), - ) - : navigationDistance(), + : navigationBox(), ], ), - navigationState == 0 - ? GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - Navigator.of(context).pop(); - }, - child: Container( - height: 56.h, - margin: EdgeInsets.only( - top: MediaQuery.of(context).padding.top + 16.h, - left: 14.w, - right: 14.w), - padding: EdgeInsets.only(left: 12.w, right: 21.w), - decoration: BoxDecoration( - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Color(0x08213303), - offset: Offset(0, 2), - blurRadius: 4, - spreadRadius: 0, - ), - ], - borderRadius: BorderRadius.circular(6), - ), - child: Row( - children: [ - Icon( - Icons.arrow_back_ios, - color: Color(0xFF353535), - size: 24, - ), - Expanded( - child: Text( - storeInfo?.storeName ?? "", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: Color(0xFF0D0D0D), - fontSize: 18.sp, - fontWeight: MyFontWeight.regular, - ), - )) - ], - ), - ), - ) - : navigationBox(), + if (_isShowLocalTips) + Padding( + padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top), + child: LocationTips(() { + setState(() { + _isShowLocalTips = false; + }); + }), + ) ], ), ); } + void onOpenBaiduMap() async { + launch("baidumap://map/marker?location=${storeInfo.latitude},${storeInfo.longitude}&title=${storeInfo.storeName}&content=${storeInfo.storeName}&traffic=on&src=andr.baidu.openAPIdemo&coord_type=gcj02"); + } + //調取百度地圖APP void onOpenBaiduMapRoute() async { // 我的位置 @@ -378,15 +425,15 @@ class _LocationMap extends State { routeType: navigationType == 1 ? BMFOpenRouteType.WalkingRoute : navigationType == 2 - ? BMFOpenRouteType.WalkingRoute - : navigationType == 3 - ? BMFOpenRouteType.TransitRoute - : BMFOpenRouteType.DrivingRoute, + ? BMFOpenRouteType.WalkingRoute + : navigationType == 3 + ? BMFOpenRouteType.TransitRoute + : BMFOpenRouteType.DrivingRoute, appScheme: 'baidumapsdk_flutter://mapsdk.baidu.com', // 指定返回自定义scheme isSupportWeb: true); BMFOpenErrorCode flag = - await BMFOpenMapUtils.openBaiduMapRoute(routeOption); + await BMFOpenMapUtils.openBaiduMapRoute(routeOption); print('open - route - errorCode = $flag'); } @@ -397,15 +444,15 @@ class _LocationMap extends State { _mapController.cleanAllMarkers(); if (polylineId != null) _mapController.removeOverlay(polylineId); - BMFCoordinate startLocation = - BMFCoordinate(coordinates.first.latitude, coordinates.first.longitude); + BMFCoordinate startLocation = BMFCoordinate( + coordinates.first.latitude, coordinates.first.longitude); BMFCoordinate endLocation = - BMFCoordinate(coordinates.last.latitude, coordinates.last.longitude); + BMFCoordinate(coordinates.last.latitude, coordinates.last.longitude); /// 创建polyline BMFPolyline colorsPolyline = BMFPolyline( - // id: polylineOptions.hashCode.toString(), + // id: polylineOptions.hashCode.toString(), coordinates: coordinates, indexs: [0], textures: [ @@ -442,13 +489,13 @@ class _LocationMap extends State { visibleMapBounds: BMFCoordinateBounds( northeast: startLocation, southwest: endLocation), animated: true, - insets: EdgeInsets.only( - top: 500, bottom: 200, left: 200, right: 200)); + insets: + EdgeInsets.only(top: 500, bottom: 200, left: 200, right: 200)); hours = needHours == 0 ? "" : "$needHours小时"; minutes = needMinutes == 0 ? "" : "$needMinutes分钟"; distance = needDistance; - }finally{ + } finally { setState(() {}); EasyLoading.dismiss(); } @@ -472,7 +519,7 @@ class _LocationMap extends State { if (navigationType == 1) { //步行 BMFWalkingRoutePlanOption walkingRoutePlanOption = - BMFWalkingRoutePlanOption(from: from, to: to); + BMFWalkingRoutePlanOption(from: from, to: to); // 检索实例 BMFWalkingRouteSearch walkingRouteSearch = BMFWalkingRouteSearch(); // 检索回调 @@ -504,11 +551,11 @@ class _LocationMap extends State { result.routes.first.distance.toDouble()); }); bool flag = - await walkingRouteSearch.walkingRouteSearch(walkingRoutePlanOption); + await walkingRouteSearch.walkingRouteSearch(walkingRoutePlanOption); } else if (navigationType == 2) { //骑行 BMFRidingRoutePlanOption ridingRoutePlanOption = - BMFRidingRoutePlanOption(from: from, to: to); + BMFRidingRoutePlanOption(from: from, to: to); BMFRidingRouteSearch ridingRouteSearch = BMFRidingRouteSearch(); ridingRouteSearch.onGetRidingRouteSearchResult(callback: (BMFRidingRouteResult result, BMFSearchErrorCode errorCode) { @@ -539,11 +586,11 @@ class _LocationMap extends State { }); // 发起检索 bool flag = - await ridingRouteSearch.ridingRouteSearch(ridingRoutePlanOption); + await ridingRouteSearch.ridingRouteSearch(ridingRoutePlanOption); } else if (navigationType == 3) { //公交 BMFTransitRoutePlanOption transitRoutePlanOption = - BMFTransitRoutePlanOption(from: from, to: to, city: '武汉市'); + BMFTransitRoutePlanOption(from: from, to: to, city: '武汉市'); BMFTransitRouteSearch transitRouteSearch = BMFTransitRouteSearch(); transitRouteSearch.onGetTransitRouteSearchResult(callback: (BMFTransitRouteResult result, BMFSearchErrorCode errorCode) { @@ -574,11 +621,11 @@ class _LocationMap extends State { }); // 发起检索 bool flag = - await transitRouteSearch.transitRouteSearch(transitRoutePlanOption); + await transitRouteSearch.transitRouteSearch(transitRoutePlanOption); } else { //驾车 BMFDrivingRoutePlanOption drivingRoutePlanOption = - BMFDrivingRoutePlanOption(from: from, to: to); + BMFDrivingRoutePlanOption(from: from, to: to); BMFDrivingRouteSearch drivingRouteSearch = BMFDrivingRouteSearch(); drivingRouteSearch.onGetDrivingRouteSearchResult(callback: (BMFDrivingRouteResult result, BMFSearchErrorCode errorCode) { @@ -609,7 +656,7 @@ class _LocationMap extends State { }); // 发起检索 bool flag = - await drivingRouteSearch.dringRouteSearch(drivingRoutePlanOption); + await drivingRouteSearch.dringRouteSearch(drivingRoutePlanOption); } } @@ -654,279 +701,279 @@ class _LocationMap extends State { ), Expanded( child: Column( + children: [ + Container( + width: double.infinity, + decoration: BoxDecoration( + color: Color(0xFFF5F5F5), + borderRadius: BorderRadius.circular(6), + ), + padding: EdgeInsets.only( + top: 12.h, + bottom: 12.h, + left: 15.w, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: EdgeInsets.only( + bottom: 14.h, + ), + child: Row( + children: [ + Container( + width: 4.h, + height: 4.h, + margin: EdgeInsets.only(right: 20.w), + decoration: BoxDecoration( + color: Color(0xFF32A060), + borderRadius: BorderRadius.circular(6), + ), + ), + Expanded( + child: Text( + positionSorta == false + ? "我的位置" + : (storeInfo?.storeName ?? ""), + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Color(0xFF0D0D0D), + fontSize: 14.sp, + fontWeight: MyFontWeight.semi_bold, + ), + )) + ], + ), + ), + Row( + children: [ + Container( + width: 4.h, + height: 4.h, + margin: EdgeInsets.only(right: 20.w), + decoration: BoxDecoration( + color: Color(0xFFFA5151), + borderRadius: BorderRadius.circular(6), + ), + ), + Expanded( + child: Text( + positionSorta == false + ? (storeInfo?.storeName ?? "") + : "我的位置", + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Color(0xFF0D0D0D), + fontSize: 14.sp, + fontWeight: MyFontWeight.semi_bold, + ), + )) + ], + ) + ], + )), + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + positionSorta = !positionSorta; + navigationPosition(); + }, + child: Container( + padding: EdgeInsets.only(right: 24.w), + child: Image.asset( + "assets/image/position_sort.webp", + fit: BoxFit.fill, + height: 16.h, + width: 14.w, + ), + ), + ) + ], + ), + ), + SizedBox( + height: 12.h, + ), + Row( children: [ - Container( - width: double.infinity, - decoration: BoxDecoration( - color: Color(0xFFF5F5F5), - borderRadius: BorderRadius.circular(6), - ), - padding: EdgeInsets.only( - top: 12.h, - bottom: 12.h, - left: 15.w, + Expanded( + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + navigationType = 4; + navigationPosition(); + }, + child: Container( + decoration: BoxDecoration( + color: navigationType == 4 + ? Color(0xFFE8FFF2) + : Colors.transparent, + borderRadius: BorderRadius.circular(23), + ), + padding: + EdgeInsets.symmetric(vertical: 5.h, horizontal: 13.w), + child: Row( + children: [ + if (navigationType == 4) + Image.asset( + "assets/image/icon_drive.webp", + fit: BoxFit.fill, + height: 16.h, + width: 14.w, + ), + Padding( + padding: EdgeInsets.only(left: 2.w), + child: Text( + "驾车", + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: navigationType == 4 + ? Color(0xFF32A060) + : Colors.black, + fontSize: 12.sp, + fontWeight: MyFontWeight.medium, + ), + ), + ) + ], + ), ), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + )), + Expanded( + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + navigationType = 3; + navigationPosition(); + }, + child: Container( + decoration: BoxDecoration( + color: navigationType == 3 + ? Color(0xFFE8FFF2) + : Colors.transparent, + borderRadius: BorderRadius.circular(23), + ), + padding: EdgeInsets.symmetric( + vertical: 5.h, horizontal: 13.w), + child: Row( children: [ + if (navigationType == 3) + Image.asset( + "assets/image/icon_transit.webp", + fit: BoxFit.fill, + height: 16.h, + width: 14.w, + ), Padding( - padding: EdgeInsets.only( - bottom: 14.h, + padding: EdgeInsets.only(left: 2.w), + child: Text( + "公交", + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: navigationType == 3 + ? Color(0xFF32A060) + : Colors.black, + fontSize: 12.sp, + fontWeight: MyFontWeight.medium, + ), ), - child: Row( - children: [ - Container( - width: 4.h, - height: 4.h, - margin: EdgeInsets.only(right: 20.w), - decoration: BoxDecoration( - color: Color(0xFF32A060), - borderRadius: BorderRadius.circular(6), - ), - ), - Expanded( - child: Text( - positionSorta == false - ? "我的位置" - : (storeInfo?.storeName ?? ""), - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: Color(0xFF0D0D0D), - fontSize: 14.sp, - fontWeight: MyFontWeight.semi_bold, - ), - )) - ], + ) + ], + ), + ))), + Expanded( + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + navigationType = 2; + navigationPosition(); + }, + child: Container( + decoration: BoxDecoration( + color: navigationType == 2 + ? Color(0xFFE8FFF2) + : Colors.transparent, + borderRadius: BorderRadius.circular(23), + ), + padding: EdgeInsets.symmetric( + vertical: 5.h, horizontal: 13.w), + child: Row( + children: [ + if (navigationType == 2) + Image.asset( + "assets/image/icon_by_bike.webp", + fit: BoxFit.fill, + height: 16.h, + width: 14.w, ), - ), - Row( - children: [ - Container( - width: 4.h, - height: 4.h, - margin: EdgeInsets.only(right: 20.w), - decoration: BoxDecoration( - color: Color(0xFFFA5151), - borderRadius: BorderRadius.circular(6), - ), + Padding( + padding: EdgeInsets.only(left: 2.w), + child: Text( + "骑行", + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: navigationType == 2 + ? Color(0xFF32A060) + : Colors.black, + fontSize: 12.sp, + fontWeight: MyFontWeight.medium, ), - Expanded( - child: Text( - positionSorta == false - ? (storeInfo?.storeName ?? "") - : "我的位置", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: Color(0xFF0D0D0D), - fontSize: 14.sp, - fontWeight: MyFontWeight.semi_bold, - ), - )) - ], + ), ) ], - )), - GestureDetector( + ), + ))), + Expanded( + child: GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { - positionSorta = !positionSorta; + navigationType = 1; navigationPosition(); }, child: Container( - padding: EdgeInsets.only(right: 24.w), - child: Image.asset( - "assets/image/position_sort.webp", - fit: BoxFit.fill, - height: 16.h, - width: 14.w, + decoration: BoxDecoration( + color: navigationType == 1 + ? Color(0xFFE8FFF2) + : Colors.transparent, + borderRadius: BorderRadius.circular(23), ), - ), - ) - ], - ), - ), - SizedBox( - height: 12.h, - ), - Row( - children: [ - Expanded( - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - navigationType = 4; - navigationPosition(); - }, - child: Container( - decoration: BoxDecoration( - color: navigationType == 4 - ? Color(0xFFE8FFF2) - : Colors.transparent, - borderRadius: BorderRadius.circular(23), - ), - padding: - EdgeInsets.symmetric(vertical: 5.h, horizontal: 13.w), - child: Row( - children: [ - if (navigationType == 4) - Image.asset( - "assets/image/icon_drive.webp", - fit: BoxFit.fill, - height: 16.h, - width: 14.w, - ), - Padding( - padding: EdgeInsets.only(left: 2.w), - child: Text( - "驾车", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: navigationType == 4 - ? Color(0xFF32A060) - : Colors.black, - fontSize: 12.sp, - fontWeight: MyFontWeight.medium, - ), + padding: EdgeInsets.symmetric( + vertical: 5.h, horizontal: 13.w), + child: Row( + children: [ + if (navigationType == 1) + Image.asset( + "assets/image/icon_walk.webp", + fit: BoxFit.fill, + height: 16.h, + width: 14.w, + ), + Padding( + padding: EdgeInsets.only(left: 2.w), + child: Text( + "步行", + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: navigationType == 1 + ? Color(0xFF32A060) + : Colors.black, + fontSize: 12.sp, + fontWeight: MyFontWeight.medium, ), - ) - ], - ), + ), + ) + ], ), - )), - Expanded( - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - navigationType = 3; - navigationPosition(); - }, - child: Container( - decoration: BoxDecoration( - color: navigationType == 3 - ? Color(0xFFE8FFF2) - : Colors.transparent, - borderRadius: BorderRadius.circular(23), - ), - padding: EdgeInsets.symmetric( - vertical: 5.h, horizontal: 13.w), - child: Row( - children: [ - if (navigationType == 3) - Image.asset( - "assets/image/icon_transit.webp", - fit: BoxFit.fill, - height: 16.h, - width: 14.w, - ), - Padding( - padding: EdgeInsets.only(left: 2.w), - child: Text( - "公交", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: navigationType == 3 - ? Color(0xFF32A060) - : Colors.black, - fontSize: 12.sp, - fontWeight: MyFontWeight.medium, - ), - ), - ) - ], - ), - ))), - Expanded( - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - navigationType = 2; - navigationPosition(); - }, - child: Container( - decoration: BoxDecoration( - color: navigationType == 2 - ? Color(0xFFE8FFF2) - : Colors.transparent, - borderRadius: BorderRadius.circular(23), - ), - padding: EdgeInsets.symmetric( - vertical: 5.h, horizontal: 13.w), - child: Row( - children: [ - if (navigationType == 2) - Image.asset( - "assets/image/icon_by_bike.webp", - fit: BoxFit.fill, - height: 16.h, - width: 14.w, - ), - Padding( - padding: EdgeInsets.only(left: 2.w), - child: Text( - "骑行", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: navigationType == 2 - ? Color(0xFF32A060) - : Colors.black, - fontSize: 12.sp, - fontWeight: MyFontWeight.medium, - ), - ), - ) - ], - ), - ))), - Expanded( - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - navigationType = 1; - navigationPosition(); - }, - child: Container( - decoration: BoxDecoration( - color: navigationType == 1 - ? Color(0xFFE8FFF2) - : Colors.transparent, - borderRadius: BorderRadius.circular(23), - ), - padding: EdgeInsets.symmetric( - vertical: 5.h, horizontal: 13.w), - child: Row( - children: [ - if (navigationType == 1) - Image.asset( - "assets/image/icon_walk.webp", - fit: BoxFit.fill, - height: 16.h, - width: 14.w, - ), - Padding( - padding: EdgeInsets.only(left: 2.w), - child: Text( - "步行", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: navigationType == 1 - ? Color(0xFF32A060) - : Colors.black, - fontSize: 12.sp, - fontWeight: MyFontWeight.medium, - ), - ), - ) - ], - ), - ))), - ], - ) + ))), ], - )) + ) + ], + )) ], ), ); @@ -972,10 +1019,10 @@ class _LocationMap extends State { child: Text( (distance ?? 0) > 1000 ? S.of(context).gongli( - ((distance ?? 0) / 1000 * 100).toInt() / 100.0) + ((distance ?? 0) / 1000 * 100).toInt() / 100.0) : S - .of(context) - .mi(((distance ?? 0) * 100).toInt() / 100.0), + .of(context) + .mi(((distance ?? 0) * 100).toInt() / 100.0), overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 20.sp, @@ -1008,10 +1055,10 @@ class _LocationMap extends State { navigationType == 1 ? "步行导航" : navigationType == 2 - ? "骑行导航" - : navigationType == 3 - ? "公交导航" - : "驾车导航", + ? "骑行导航" + : navigationType == 3 + ? "公交导航" + : "驾车导航", style: TextStyle( fontSize: 20.sp, color: Colors.white, @@ -1030,19 +1077,19 @@ class _LocationMap extends State { var list = businessService.split(","); return list .map((e) => Container( - margin: EdgeInsets.only(right: 8.w), - child: RoundButton( - height: 17.h * AppUtils.textScale(context), - text: "$e", - backgroup: Color(0xFFFF7A1A), - padding: EdgeInsets.only( - left: 2.w, - right: 2.w, - ), - fontSize: 10.sp, - textColor: Colors.white, - ), - )) + margin: EdgeInsets.only(right: 8.w), + child: RoundButton( + height: 17.h * AppUtils.textScale(context), + text: "$e", + backgroup: Color(0xFFFF7A1A), + padding: EdgeInsets.only( + left: 2.w, + right: 2.w, + ), + fontSize: 10.sp, + textColor: Colors.white, + ), + )) .toList(); } @@ -1064,7 +1111,7 @@ class _LocationMap extends State { isAccuracyCircleShow: true, locationViewImage: 'assets/image/icon_my_location.webp', locationViewHierarchy: - BMFLocationViewHierarchy.LOCATION_VIEW_HIERARCHY_BOTTOM, + BMFLocationViewHierarchy.LOCATION_VIEW_HIERARCHY_BOTTOM, ); _mapController.updateLocationViewWithParam(displayParam); addMarker(); diff --git a/lib/union/union_page.dart b/lib/union/union_page.dart index 95631d64..3bcb69bd 100644 --- a/lib/union/union_page.dart +++ b/lib/union/union_page.dart @@ -21,6 +21,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; +import '../view_widget/location_tips.dart'; import '../view_widget/no_data_view.dart'; class UnionPage extends StatefulWidget { @@ -45,6 +46,7 @@ class UnionPageState extends State BMFCoordinate latLng; String areaName; List _allKey = []; + bool _isShowLocalTips = false; jumpIndex(jpIndex) { tabController.index = jpIndex; @@ -59,6 +61,23 @@ class UnionPageState extends State Location.getInstance().aMapFlutterLocation.stopLocation(); } + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + if (state == AppLifecycleState.resumed) { + // 处理应用程序切换回前台的逻辑 + permissionSettings(); + } else if (state == AppLifecycleState.paused) { + // 处理应用程序切换到后台的逻辑 + } + } + + void permissionSettings() async { + if (await Permission.location.isGranted){ + _isShowLocalTips = false; + startLocation(); + } + } + @override void didChangeMetrics() { super.didChangeMetrics(); @@ -127,8 +146,10 @@ class UnionPageState extends State if (!powerFlag) { if (await Permission.locationWhenInUse.status.isGranted) { startLocation(); - } else + } else { + _isShowLocalTips = true; loadFinish(showLoading: false); + } } } } @@ -185,120 +206,134 @@ class UnionPageState extends State onTap: () { FocusScope.of(context).requestFocus(FocusNode()); }, - child: Container( - child: Column( - children: [ - Row( + child: Stack( + alignment: Alignment.bottomCenter, + children: [ + Container( + child: Column( children: [ - Padding( - padding: EdgeInsets.only(left: 18.w, right: 10.w), - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - Navigator.of(context).pushNamed( - '/router/union_select_city', - arguments: {"cityName": areaName}).then((value) { - if (value != null) { - areaName = value; - loadFinish(); - } - }); - }, - child: Row( - children: [ - Text( - areaName ?? "", - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: TextStyle( - fontSize: 14.sp, - fontWeight: FontWeight.bold, - color: Colors.white), + Row( + children: [ + Padding( + padding: EdgeInsets.only(left: 18.w, right: 10.w), + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + Navigator.of(context).pushNamed( + '/router/union_select_city', + arguments: {"cityName": areaName}).then((value) { + if (value != null) { + areaName = value; + loadFinish(); + } + }); + }, + child: Row( + children: [ + Text( + areaName ?? "", + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: TextStyle( + fontSize: 14.sp, + fontWeight: FontWeight.bold, + color: Colors.white), + ), + Icon( + Icons.keyboard_arrow_down, + color: Colors.white, + size: 24, + ) + ], ), - Icon( - Icons.keyboard_arrow_down, - color: Colors.white, - size: 24, - ) - ], + ), + ), + Expanded(child: buildSearchItem()) + ], + ), + Align( + alignment: Alignment.centerLeft, + child: TabBar( + controller: tabController, + isScrollable: true, + //可滚动 + indicatorColor: Colors.white, + labelColor: Colors.white, + labelStyle: TextStyle( + fontSize: 18.sp, + fontWeight: FontWeight.bold, + ), + unselectedLabelStyle: TextStyle( + fontSize: 15.sp, + fontWeight: FontWeight.normal, ), + //未选中文字颜色 + unselectedLabelColor: Colors.white, + indicatorSize: TabBarIndicatorSize.label, + //指示器与文字等宽 + tabs: [ + MyTab(text: S.of(context).quanbu), + MyTab(text: S.of(context).chi), + MyTab(text: S.of(context).he), + MyTab(text: S.of(context).wan), + ], ), ), - Expanded(child: buildSearchItem()) + _allKey.isEmpty + ? NoDataView( + src: "assets/image/di_zhi.webp", + isShowBtn: false, + text: "暂无店铺列表~", + fontSize: 16.sp, + margin: EdgeInsets.only(top: 120.h), + ) + : Expanded( + child: TabBarView( + controller: tabController, + children: [ + UnionList(_allKey[0], "", latLng, + editingController.text, areaName), + UnionList(_allKey[1], "EATSTORE", latLng, + editingController.text, areaName), + UnionList(_allKey[2], "DRINKSTORE", latLng, + editingController.text, areaName), + UnionList(_allKey[3], "HAPPYSTORE", latLng, + editingController.text, areaName), + ], + ), + ) ], ), - Align( - alignment: Alignment.centerLeft, - child: TabBar( - controller: tabController, - isScrollable: true, - //可滚动 - indicatorColor: Colors.white, - labelColor: Colors.white, - labelStyle: TextStyle( - fontSize: 18.sp, - fontWeight: FontWeight.bold, - ), - unselectedLabelStyle: TextStyle( - fontSize: 15.sp, - fontWeight: FontWeight.normal, - ), - //未选中文字颜色 - unselectedLabelColor: Colors.white, - indicatorSize: TabBarIndicatorSize.label, - //指示器与文字等宽 - tabs: [ - MyTab(text: S.of(context).quanbu), - MyTab(text: S.of(context).chi), - MyTab(text: S.of(context).he), - MyTab(text: S.of(context).wan), - ], - ), + padding: + EdgeInsets.only(top: MediaQuery.of(context).padding.top + 17.h), + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + Color(0xFF32A060), + Color(0xFF32A060), + Colors.white, + Colors.white, + ], + stops: [ + 0, + 0.2, + 0.4, + 1 + ]), ), - _allKey.isEmpty - ? NoDataView( - src: "assets/image/di_zhi.webp", - isShowBtn: false, - text: "暂无店铺列表~", - fontSize: 16.sp, - margin: EdgeInsets.only(top: 120.h), - ) - : Expanded( - child: TabBarView( - controller: tabController, - children: [ - UnionList(_allKey[0], "", latLng, - editingController.text, areaName), - UnionList(_allKey[1], "EATSTORE", latLng, - editingController.text, areaName), - UnionList(_allKey[2], "DRINKSTORE", latLng, - editingController.text, areaName), - UnionList(_allKey[3], "HAPPYSTORE", latLng, - editingController.text, areaName), - ], - ), - ) - ], - ), - padding: - EdgeInsets.only(top: MediaQuery.of(context).padding.top + 17.h), - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - Color(0xFF32A060), - Color(0xFF32A060), - Colors.white, - Colors.white, - ], - stops: [ - 0, - 0.2, - 0.4, - 1 - ]), - ), + ), + if (_isShowLocalTips) + Padding( + padding: EdgeInsets.only(bottom: 70.h), + child: LocationTips(() { + setState(() { + _isShowLocalTips = false; + }); + }), + ) + ], ), ); } diff --git a/lib/utils/location.dart b/lib/utils/location.dart index f678878c..2b1f1482 100644 --- a/lib/utils/location.dart +++ b/lib/utils/location.dart @@ -11,10 +11,9 @@ import 'package:permission_handler/permission_handler.dart'; import 'font_weight.dart'; - BaiduLocationAndroidOption initAndroidOptions() { BaiduLocationAndroidOption options = BaiduLocationAndroidOption( - // 定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式 + // 定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式 locationMode: BMFLocationMode.hightAccuracy, // 是否需要返回地址信息 isNeedAddress: true, @@ -63,7 +62,6 @@ BaiduLocationIOSOption initIOSOptions() { return options; } - class Location { static Location _instance; @@ -80,17 +78,18 @@ class Location { LocationFlutterPlugin aMapFlutterLocation; - Future startLocation(context, Function(BaiduLocation result) locationCallback) async { - aMapFlutterLocation.prepareLoc(initAndroidOptions().getMap(), initIOSOptions().getMap()); - if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) { - enableLocation(context); + Future startLocation( + context, Function(BaiduLocation result) locationCallback) async { + aMapFlutterLocation.prepareLoc( + initAndroidOptions().getMap(), initIOSOptions().getMap()); + var permissionStatus = await Permission.location.status; + if (!permissionStatus.isGranted) { + if (permissionStatus.isUndetermined) + showTipsAlertDialog(context); return false; - } - if (await Permission.location.isPermanentlyDenied) { - requestDialog(context, locationCallback); - return false; - } else if (await Permission.location.isGranted) { - aMapFlutterLocation.singleLocationCallback(callback: (BaiduLocation result) { + } else { + aMapFlutterLocation.singleLocationCallback( + callback: (BaiduLocation result) { locationCallback.call(result); }); if (Platform.isIOS) { @@ -102,21 +101,6 @@ class Location { await aMapFlutterLocation.startLocation(); } return true; - } else if (await Permission.location.isUndetermined) { - showAlertDialog(context); - await Permission.location.request(); - Navigator.of(context).pop(); - return false; - } else { - if (Platform.isIOS) { - //去设置中心 - requestDialog(context, locationCallback); - } else { - showAlertDialog(context); - await Permission.location.request(); - Navigator.of(context).pop(); - } - return false; } } @@ -172,56 +156,173 @@ class Location { } ///定位权限说明弹窗 - showAlertDialog(context) { + showTipsAlertDialog(context) async { //显示对话框 showDialog( context: context, + barrierDismissible: false, + barrierColor: null, builder: (BuildContext context) { - return SimpleDialog( - titlePadding: EdgeInsets.all(10), - backgroundColor: Colors.transparent, - elevation: 0, - alignment: Alignment.topCenter, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(6), - ), - children: [ + return Column( + children: [ Container( width: double.infinity, - height: 120.h, - padding: EdgeInsets.all(16), + padding: EdgeInsets.all(15), + margin: EdgeInsets.all(15), decoration: new BoxDecoration( color: Colors.white, - borderRadius: BorderRadius.circular(8), + borderRadius: BorderRadius.circular(10), ), - child:Column( + child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - "访问精确地理位置信息权限说明", - style: TextStyle( - fontSize: 15.sp, - fontWeight:MyFontWeight.regular, - color: Colors.black, - ), + Icon( + Icons.location_on_outlined, + color: Colors.black, + size: 22, ), - SizedBox(height: 3.h,), - Text( - "为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息,不授权该权限不影响app正常使用。", - style: TextStyle( - fontSize: 13.sp, - height: 1.3.h, - fontWeight:MyFontWeight.regular, - color: Colors.black, + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + // "访问精确地理位置信息权限说明", + "位置权限使用说明", + style: TextStyle( + fontSize: 18.sp, + fontWeight: MyFontWeight.regular, + color: Colors.black, + ), + ), + SizedBox( + height: 3.h, + ), + Text( + // "为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息,不授权该权限不影响app正常使用。", + "为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息", + style: TextStyle( + fontSize: 13.sp, + fontWeight: MyFontWeight.regular, + color: Colors.black, + ), + ), + ], ), ), ], ), - ), + ) ], + mainAxisSize: MainAxisSize.min, ); }, ); + await Permission.location.request(); + Navigator.of(context).pop(); } + ///定位权限说明和申请弹窗 + showAlertDialog(context) { + //显示对话框 + showDialog( + context: context, + barrierDismissible: true, + barrierColor: null, + builder: (BuildContext context) { + return Column( + children: [ + Container( + width: double.infinity, + padding: EdgeInsets.all(15), + margin: EdgeInsets.all(15), + decoration: new BoxDecoration( + color: Colors.black.withOpacity(0.6), + borderRadius: BorderRadius.circular(10), + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + // "访问精确地理位置信息权限说明", + "定位服务未开启", + style: TextStyle( + fontSize: 18.sp, + fontWeight: MyFontWeight.regular, + color: Colors.white, + ), + ), + SizedBox( + height: 3.h, + ), + Text( + // "为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息,不授权该权限不影响app正常使用。", + "开启后才能提供更详细的定位服务哦!", + style: TextStyle( + fontSize: 13.sp, + fontWeight: MyFontWeight.regular, + color: Colors.white, + ), + ), + ], + ), + ), + GestureDetector( + child: Container( + child: Text( + "去开启", + style: TextStyle( + fontSize: 15.sp, + fontWeight: MyFontWeight.regular, + color: Colors.white, + ), + ), + margin: EdgeInsets.symmetric( + horizontal: 15.w, vertical: 25.h), + padding: + EdgeInsets.symmetric(vertical: 2.h, horizontal: 10.w), + decoration: BoxDecoration( + color: Colors.green, + borderRadius: BorderRadius.circular(100), + ), + ), + onTap: () async { + await openAppSettings(); + if (await Permission.location.isGranted) + Navigator.of(context).pop(); + }, + behavior: HitTestBehavior.opaque, + ), + GestureDetector( + behavior: HitTestBehavior.opaque, + child: Container( + child: Icon( + Icons.close, + color: Colors.white.withOpacity(0.8), + size: 12, + ), + decoration: BoxDecoration( + color: Colors.black.withOpacity(0.8), + borderRadius: BorderRadius.circular(100), + ), + padding: EdgeInsets.all(5), + ), + onTap: () { + Navigator.of(context).pop(); + }, + ) + ], + ), + ) + ], + mainAxisSize: MainAxisSize.min, + ); + }, + ); + } } diff --git a/lib/view_widget/location_tips.dart b/lib/view_widget/location_tips.dart new file mode 100644 index 00000000..726b94ad --- /dev/null +++ b/lib/view_widget/location_tips.dart @@ -0,0 +1,120 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; +import 'package:huixiang/retrofit/data/activity_pos.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:permission_handler/permission_handler.dart'; + +import '../retrofit/data/login_info.dart'; +import '../utils/font_weight.dart'; +import 'custom_image.dart'; +import 'new_people_reward.dart'; + +class LocationTips extends StatefulWidget { + final Function disMissLocationTips; + + LocationTips(this.disMissLocationTips); + + @override + State createState() { + return _LocationTips(); + } +} + +class _LocationTips extends State { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Container( + width: double.infinity, + padding: EdgeInsets.all(10), + margin: EdgeInsets.only(left: 15.w, right: 15.w, bottom: 15.h), + decoration: new BoxDecoration( + color: Colors.black.withOpacity(0.8), + borderRadius: BorderRadius.circular(10), + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + // "访问精确地理位置信息权限说明", + "定位服务未开启", + style: TextStyle( + fontSize: 16.sp, + fontWeight: MyFontWeight.regular, + color: Colors.white, + ), + ), + SizedBox( + height: 3.h, + ), + Text( + // "为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息,不授权该权限不影响app正常使用。", + "开启后才能提供更详细的定位服务哦!", + style: TextStyle( + fontSize: 13.sp, + fontWeight: MyFontWeight.regular, + color: Colors.white, + ), + ), + ], + ), + ), + GestureDetector( + child: Container( + child: Text( + "去开启", + style: TextStyle( + fontSize: 13.sp, + fontWeight: MyFontWeight.regular, + color: Colors.white, + ), + ), + margin: EdgeInsets.only(left: 15.w, right: 15.w, top: 15.h), + padding: EdgeInsets.symmetric(vertical: 2.h, horizontal: 10.w), + decoration: BoxDecoration( + color: Colors.green, + borderRadius: BorderRadius.circular(100), + ), + ), + onTap: () async { + if (!await openAppSettings()) { + SmartDialog.showToast("打开应用设置失败,请手动前往系统设置中心开启应用位置权限", + alignment: Alignment.center); + } + }, + behavior: HitTestBehavior.opaque, + ), + GestureDetector( + behavior: HitTestBehavior.opaque, + child: Container( + child: Icon( + Icons.close, + color: Colors.white.withOpacity(0.8), + size: 10, + ), + decoration: BoxDecoration( + color: Colors.black.withOpacity(0.8), + borderRadius: BorderRadius.circular(100), + ), + padding: EdgeInsets.all(3), + ), + onTap: () { + widget.disMissLocationTips(); + }, + ) + ], + ), + ); + } +}