Browse Source

Merge remote-tracking branch 'origin/wu_2023_map' into wu_2023_map

dev
huixiang_app 1 year ago
parent
commit
02c050d4d9
  1. 1
      lib/main.dart
  2. 81
      lib/union/location_map_page.dart
  3. 39
      lib/union/union_page.dart
  4. 191
      lib/utils/location.dart
  5. 120
      lib/view_widget/location_tips.dart

1
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';

81
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<LocationMap> {
class _LocationMap extends State<LocationMap> with WidgetsBindingObserver {
StoreInfo storeInfo;
int navigationState = 0;
double distance;
@ -42,10 +44,12 @@ class _LocationMap extends State<LocationMap> {
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();
@ -66,8 +70,7 @@ class _LocationMap extends State<LocationMap> {
myLatLng = BMFCoordinate(result.latitude, result.longitude);
myAddress = result.locationDetail;
myCity = result.city;
if(distance == null)
calculate();
if (distance == null) calculate();
AppUtils.coordConvert(myLatLng).then((value) {
this.myLatLng = value;
locationShow();
@ -80,9 +83,12 @@ class _LocationMap extends State<LocationMap> {
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<LocationMap> {
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<LocationMap> {
@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
@ -129,6 +154,8 @@ class _LocationMap extends State<LocationMap> {
// leadingColor: Colors.black,
// ),
body: Stack(
children: [
Stack(
children: [
Column(
children: [
@ -153,8 +180,8 @@ class _LocationMap extends State<LocationMap> {
navigationState == 0
? Container(
height: 253.h,
padding:
EdgeInsets.only(top: 16.h, left: 16.w, right: 28.w),
padding: EdgeInsets.only(
top: 16.h, left: 16.w, right: 28.w),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
@ -199,14 +226,16 @@ class _LocationMap extends State<LocationMap> {
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
fontWeight:
MyFontWeight.regular,
color: Color(0xFF4D4D4D),
),
),
SizedBox(
width: 20.w,
),
]..addAll(itemServer(storeInfo != null
]..addAll(itemServer(
storeInfo != null
? storeInfo.businessService
: "")),
),
@ -262,14 +291,17 @@ class _LocationMap extends State<LocationMap> {
behavior: HitTestBehavior.opaque,
onTap: () {
if (myCity == null) {
getLocation();
// 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;
else
navigationType = 4;
navigationPosition();
}
},
@ -347,9 +379,24 @@ class _LocationMap extends State<LocationMap> {
: 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 {
//
@ -397,8 +444,8 @@ class _LocationMap extends State<LocationMap> {
_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);
@ -442,8 +489,8 @@ class _LocationMap extends State<LocationMap> {
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分钟";

39
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<UnionPage>
BMFCoordinate latLng;
String areaName;
List<GlobalKey> _allKey = [];
bool _isShowLocalTips = false;
jumpIndex(jpIndex) {
tabController.index = jpIndex;
@ -59,6 +61,23 @@ class UnionPageState extends State<UnionPage>
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,11 +146,13 @@ class UnionPageState extends State<UnionPage>
if (!powerFlag) {
if (await Permission.locationWhenInUse.status.isGranted) {
startLocation();
} else
} else {
_isShowLocalTips = true;
loadFinish(showLoading: false);
}
}
}
}
saveLatLng(BMFCoordinate latLng, province, city, district) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
@ -185,7 +206,10 @@ class UnionPageState extends State<UnionPage>
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: Container(
child: Stack(
alignment: Alignment.bottomCenter,
children: [
Container(
child: Column(
children: [
Row(
@ -300,6 +324,17 @@ class UnionPageState extends State<UnionPage>
]),
),
),
if (_isShowLocalTips)
Padding(
padding: EdgeInsets.only(bottom: 70.h),
child: LocationTips(() {
setState(() {
_isShowLocalTips = false;
});
}),
)
],
),
);
}

191
lib/utils/location.dart

@ -11,7 +11,6 @@ import 'package:permission_handler/permission_handler.dart';
import 'font_weight.dart';
BaiduLocationAndroidOption initAndroidOptions() {
BaiduLocationAndroidOption options = BaiduLocationAndroidOption(
//
@ -63,7 +62,6 @@ BaiduLocationIOSOption initIOSOptions() {
return options;
}
class Location {
static Location _instance;
@ -80,17 +78,18 @@ class Location {
LocationFlutterPlugin aMapFlutterLocation;
Future<bool> startLocation(context, Function(BaiduLocation result) locationCallback) async {
aMapFlutterLocation.prepareLoc(initAndroidOptions().getMap(), initIOSOptions().getMap());
if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) {
enableLocation(context);
return false;
}
if (await Permission.location.isPermanentlyDenied) {
requestDialog(context, locationCallback);
Future<bool> 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;
} 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,45 +156,53 @@ 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: <Widget>[
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: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
Icons.location_on_outlined,
color: Colors.black,
size: 22,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
"访问精确地理位置信息权限说明",
// "访问精确地理位置信息权限说明",
"位置权限使用说明",
style: TextStyle(
fontSize: 15.sp,
fontSize: 18.sp,
fontWeight: MyFontWeight.regular,
color: Colors.black,
),
),
SizedBox(height: 3.h,),
SizedBox(
height: 3.h,
),
Text(
"为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息,不授权该权限不影响app正常使用。",
// "为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息,不授权该权限不影响app正常使用。",
"为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息",
style: TextStyle(
fontSize: 13.sp,
height: 1.3.h,
fontWeight: MyFontWeight.regular,
color: Colors.black,
),
@ -219,9 +211,118 @@ class Location {
),
),
],
),
)
],
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,
);
},
);
}
}

120
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<StatefulWidget> createState() {
return _LocationTips();
}
}
class _LocationTips extends State<LocationTips> {
@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();
},
)
],
),
);
}
}
Loading…
Cancel
Save