Browse Source

适配更改

dev
wurong 1 year ago
parent
commit
b6c99666cc
  1. 1
      lib/main.dart
  2. 83
      lib/union/location_map_page.dart
  3. 39
      lib/union/union_page.dart
  4. 197
      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/store/store_view/product_meals_sku.dart';
import 'package:huixiang/test_page.dart'; import 'package:huixiang/test_page.dart';
import 'package:huixiang/union/location_map_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/union/union_select_city.dart';
import 'package:huixiang/utils/ImgCachePath.dart'; import 'package:huixiang/utils/ImgCachePath.dart';
import 'package:huixiang/vip/user_vip_service_page.dart'; import 'package:huixiang/vip/user_vip_service_page.dart';

83
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:huixiang/view_widget/my_appbar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:url_launcher/url_launcher.dart';
import '../generated/l10n.dart'; import '../generated/l10n.dart';
import '../retrofit/data/store_info.dart'; import '../retrofit/data/store_info.dart';
import '../view_widget/custom_image.dart'; import '../view_widget/custom_image.dart';
import '../view_widget/location_tips.dart';
import '../view_widget/round_button.dart'; import '../view_widget/round_button.dart';
class LocationMap extends StatefulWidget { 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; StoreInfo storeInfo;
int navigationState = 0; int navigationState = 0;
double distance; double distance;
@ -42,10 +44,12 @@ class _LocationMap extends State<LocationMap> {
String hours; String hours;
String minutes; String minutes;
String polylineId; String polylineId;
bool _isShowLocalTips = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
WidgetsBinding.instance.addObserver(this);
storeInfo = widget.arguments["storeInfo"]; storeInfo = widget.arguments["storeInfo"];
distance = widget.arguments["distance"]; distance = widget.arguments["distance"];
getLocation(); getLocation();
@ -66,8 +70,7 @@ class _LocationMap extends State<LocationMap> {
myLatLng = BMFCoordinate(result.latitude, result.longitude); myLatLng = BMFCoordinate(result.latitude, result.longitude);
myAddress = result.locationDetail; myAddress = result.locationDetail;
myCity = result.city; myCity = result.city;
if(distance == null) if (distance == null) calculate();
calculate();
AppUtils.coordConvert(myLatLng).then((value) { AppUtils.coordConvert(myLatLng).then((value) {
this.myLatLng = value; this.myLatLng = value;
locationShow(); locationShow();
@ -80,9 +83,12 @@ class _LocationMap extends State<LocationMap> {
if (await Permission.locationWhenInUse.status.isGranted) { if (await Permission.locationWhenInUse.status.isGranted) {
getLocation(); getLocation();
} else { } else {
SmartDialog.showToast("您定位服务未开启,请前往系统设置中开启定位服务", _isShowLocalTips = true;
alignment: Alignment.center);
} }
// else {
// SmartDialog.showToast("您定位服务未开启,请前往系统设置中开启定位服务",
// alignment: Alignment.center);
// }
} }
} }
} }
@ -92,7 +98,8 @@ class _LocationMap extends State<LocationMap> {
double.tryParse(storeInfo.latitude), double.tryParse(storeInfo.latitude),
double.tryParse(storeInfo.longitude), 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() { locationShow() {
@ -114,8 +121,26 @@ class _LocationMap extends State<LocationMap> {
@override @override
void dispose() { void dispose() {
super.dispose(); WidgetsBinding.instance.removeObserver(this);
Location.getInstance().stopLocation(); 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 @override
@ -129,6 +154,8 @@ class _LocationMap extends State<LocationMap> {
// leadingColor: Colors.black, // leadingColor: Colors.black,
// ), // ),
body: Stack( body: Stack(
children: [
Stack(
children: [ children: [
Column( Column(
children: [ children: [
@ -153,8 +180,8 @@ class _LocationMap extends State<LocationMap> {
navigationState == 0 navigationState == 0
? Container( ? Container(
height: 253.h, height: 253.h,
padding: padding: EdgeInsets.only(
EdgeInsets.only(top: 16.h, left: 16.w, right: 28.w), top: 16.h, left: 16.w, right: 28.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
boxShadow: [ boxShadow: [
@ -199,14 +226,16 @@ class _LocationMap extends State<LocationMap> {
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
fontSize: 12.sp, fontSize: 12.sp,
fontWeight: MyFontWeight.regular, fontWeight:
MyFontWeight.regular,
color: Color(0xFF4D4D4D), color: Color(0xFF4D4D4D),
), ),
), ),
SizedBox( SizedBox(
width: 20.w, width: 20.w,
), ),
]..addAll(itemServer(storeInfo != null ]..addAll(itemServer(
storeInfo != null
? storeInfo.businessService ? storeInfo.businessService
: "")), : "")),
), ),
@ -262,14 +291,17 @@ class _LocationMap extends State<LocationMap> {
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
if (myCity == null) { if (myCity == null) {
getLocation(); // onOpenBaiduMap();
SmartDialog.showToast("您定位服务未开启,请前往系统设置中开启定位服务",
alignment: Alignment.center);
} else { } else {
navigationState = 1; navigationState = 1;
if ((distance ?? 0) < 500) if ((distance ?? 0) < 500)
navigationType = 1; navigationType = 1;
else if ((distance ?? 0) < 1500) else if ((distance ?? 0) < 1500)
navigationType = 2; navigationType = 2;
else navigationType = 4; else
navigationType = 4;
navigationPosition(); navigationPosition();
} }
}, },
@ -347,9 +379,24 @@ class _LocationMap extends State<LocationMap> {
: navigationBox(), : 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 //調APP
void onOpenBaiduMapRoute() async { void onOpenBaiduMapRoute() async {
// //
@ -397,8 +444,8 @@ class _LocationMap extends State<LocationMap> {
_mapController.cleanAllMarkers(); _mapController.cleanAllMarkers();
if (polylineId != null) _mapController.removeOverlay(polylineId); if (polylineId != null) _mapController.removeOverlay(polylineId);
BMFCoordinate startLocation = BMFCoordinate startLocation = BMFCoordinate(
BMFCoordinate(coordinates.first.latitude, coordinates.first.longitude); coordinates.first.latitude, coordinates.first.longitude);
BMFCoordinate endLocation = BMFCoordinate endLocation =
BMFCoordinate(coordinates.last.latitude, coordinates.last.longitude); BMFCoordinate(coordinates.last.latitude, coordinates.last.longitude);
@ -442,13 +489,13 @@ class _LocationMap extends State<LocationMap> {
visibleMapBounds: BMFCoordinateBounds( visibleMapBounds: BMFCoordinateBounds(
northeast: startLocation, southwest: endLocation), northeast: startLocation, southwest: endLocation),
animated: true, animated: true,
insets: EdgeInsets.only( insets:
top: 500, bottom: 200, left: 200, right: 200)); EdgeInsets.only(top: 500, bottom: 200, left: 200, right: 200));
hours = needHours == 0 ? "" : "$needHours小时"; hours = needHours == 0 ? "" : "$needHours小时";
minutes = needMinutes == 0 ? "" : "$needMinutes分钟"; minutes = needMinutes == 0 ? "" : "$needMinutes分钟";
distance = needDistance; distance = needDistance;
}finally{ } finally {
setState(() {}); setState(() {});
EasyLoading.dismiss(); EasyLoading.dismiss();
} }

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

197
lib/utils/location.dart

@ -11,7 +11,6 @@ import 'package:permission_handler/permission_handler.dart';
import 'font_weight.dart'; import 'font_weight.dart';
BaiduLocationAndroidOption initAndroidOptions() { BaiduLocationAndroidOption initAndroidOptions() {
BaiduLocationAndroidOption options = BaiduLocationAndroidOption( BaiduLocationAndroidOption options = BaiduLocationAndroidOption(
// //
@ -63,7 +62,6 @@ BaiduLocationIOSOption initIOSOptions() {
return options; return options;
} }
class Location { class Location {
static Location _instance; static Location _instance;
@ -80,17 +78,18 @@ class Location {
LocationFlutterPlugin aMapFlutterLocation; LocationFlutterPlugin aMapFlutterLocation;
Future<bool> startLocation(context, Function(BaiduLocation result) locationCallback) async { Future<bool> startLocation(
aMapFlutterLocation.prepareLoc(initAndroidOptions().getMap(), initIOSOptions().getMap()); context, Function(BaiduLocation result) locationCallback) async {
if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) { aMapFlutterLocation.prepareLoc(
enableLocation(context); initAndroidOptions().getMap(), initIOSOptions().getMap());
var permissionStatus = await Permission.location.status;
if (!permissionStatus.isGranted) {
if (permissionStatus.isUndetermined)
showTipsAlertDialog(context);
return false; return false;
} } else {
if (await Permission.location.isPermanentlyDenied) { aMapFlutterLocation.singleLocationCallback(
requestDialog(context, locationCallback); callback: (BaiduLocation result) {
return false;
} else if (await Permission.location.isGranted) {
aMapFlutterLocation.singleLocationCallback(callback: (BaiduLocation result) {
locationCallback.call(result); locationCallback.call(result);
}); });
if (Platform.isIOS) { if (Platform.isIOS) {
@ -102,21 +101,6 @@ class Location {
await aMapFlutterLocation.startLocation(); await aMapFlutterLocation.startLocation();
} }
return true; 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,46 +156,54 @@ class Location {
} }
/// ///
showAlertDialog(context) { showTipsAlertDialog(context) async {
// //
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false,
barrierColor: null,
builder: (BuildContext context) { builder: (BuildContext context) {
return SimpleDialog( return Column(
titlePadding: EdgeInsets.all(10), children: [
backgroundColor: Colors.transparent,
elevation: 0,
alignment: Alignment.topCenter,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
children: <Widget>[
Container( Container(
width: double.infinity, width: double.infinity,
height: 120.h, padding: EdgeInsets.all(15),
padding: EdgeInsets.all(16), margin: EdgeInsets.all(15),
decoration: new BoxDecoration( decoration: new BoxDecoration(
color: Colors.white, 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,
), ),
child:Column( Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [ children: [
Text( Text(
"访问精确地理位置信息权限说明", // "访问精确地理位置信息权限说明",
"位置权限使用说明",
style: TextStyle( style: TextStyle(
fontSize: 15.sp, fontSize: 18.sp,
fontWeight:MyFontWeight.regular, fontWeight: MyFontWeight.regular,
color: Colors.black, color: Colors.black,
), ),
), ),
SizedBox(height: 3.h,), SizedBox(
height: 3.h,
),
Text( Text(
"为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息,不授权该权限不影响app正常使用。", // "为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息,不授权该权限不影响app正常使用。",
"为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息",
style: TextStyle( style: TextStyle(
fontSize: 13.sp, fontSize: 13.sp,
height: 1.3.h, fontWeight: MyFontWeight.regular,
fontWeight:MyFontWeight.regular,
color: Colors.black, 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