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. 1041
      lib/union/location_map_page.dart
  3. 249
      lib/union/union_page.dart
  4. 217
      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';

1041
lib/union/location_map_page.dart

File diff suppressed because it is too large Load Diff

249
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,8 +146,10 @@ 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);
}
} }
} }
} }
@ -185,120 +206,134 @@ class UnionPageState extends State<UnionPage>
onTap: () { onTap: () {
FocusScope.of(context).requestFocus(FocusNode()); FocusScope.of(context).requestFocus(FocusNode());
}, },
child: Container( child: Stack(
child: Column( alignment: Alignment.bottomCenter,
children: [ children: [
Row( Container(
child: Column(
children: [ children: [
Padding( Row(
padding: EdgeInsets.only(left: 18.w, right: 10.w), children: [
child: GestureDetector( Padding(
behavior: HitTestBehavior.opaque, padding: EdgeInsets.only(left: 18.w, right: 10.w),
onTap: () { child: GestureDetector(
Navigator.of(context).pushNamed( behavior: HitTestBehavior.opaque,
'/router/union_select_city', onTap: () {
arguments: {"cityName": areaName}).then((value) { Navigator.of(context).pushNamed(
if (value != null) { '/router/union_select_city',
areaName = value; arguments: {"cityName": areaName}).then((value) {
loadFinish(); if (value != null) {
} areaName = value;
}); loadFinish();
}, }
child: Row( });
children: [ },
Text( child: Row(
areaName ?? "", children: [
overflow: TextOverflow.ellipsis, Text(
maxLines: 1, areaName ?? "",
style: TextStyle( overflow: TextOverflow.ellipsis,
fontSize: 14.sp, maxLines: 1,
fontWeight: FontWeight.bold, style: TextStyle(
color: Colors.white), 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, Expanded(child: buildSearchItem())
size: 24, ],
) ),
], 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: <Widget>[
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( padding:
alignment: Alignment.centerLeft, EdgeInsets.only(top: MediaQuery.of(context).padding.top + 17.h),
child: TabBar( decoration: BoxDecoration(
controller: tabController, gradient: LinearGradient(
isScrollable: true, begin: Alignment.topCenter,
// end: Alignment.bottomCenter,
indicatorColor: Colors.white, colors: [
labelColor: Colors.white, Color(0xFF32A060),
labelStyle: TextStyle( Color(0xFF32A060),
fontSize: 18.sp, Colors.white,
fontWeight: FontWeight.bold, Colors.white,
), ],
unselectedLabelStyle: TextStyle( stops: [
fontSize: 15.sp, 0,
fontWeight: FontWeight.normal, 0.2,
), 0.4,
// 1
unselectedLabelColor: Colors.white, ]),
indicatorSize: TabBarIndicatorSize.label,
//
tabs: <Widget>[
MyTab(text: S.of(context).quanbu),
MyTab(text: S.of(context).chi),
MyTab(text: S.of(context).he),
MyTab(text: S.of(context).wan),
],
),
), ),
_allKey.isEmpty ),
? NoDataView( if (_isShowLocalTips)
src: "assets/image/di_zhi.webp", Padding(
isShowBtn: false, padding: EdgeInsets.only(bottom: 70.h),
text: "暂无店铺列表~", child: LocationTips(() {
fontSize: 16.sp, setState(() {
margin: EdgeInsets.only(top: 120.h), _isShowLocalTips = false;
) });
: 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
]),
),
), ),
); );
} }

217
lib/utils/location.dart

@ -11,10 +11,9 @@ 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(
// //
locationMode: BMFLocationMode.hightAccuracy, locationMode: BMFLocationMode.hightAccuracy,
// //
isNeedAddress: true, isNeedAddress: true,
@ -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,56 +156,173 @@ 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:Column( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Icon(
"访问精确地理位置信息权限说明", Icons.location_on_outlined,
style: TextStyle( color: Colors.black,
fontSize: 15.sp, size: 22,
fontWeight:MyFontWeight.regular,
color: Colors.black,
),
), ),
SizedBox(height: 3.h,), Expanded(
Text( child: Column(
"为了向您推荐附近的门店信息,推荐您在使用期间让我们使用位置信息,不授权该权限不影响app正常使用。", crossAxisAlignment: CrossAxisAlignment.start,
style: TextStyle( mainAxisSize: MainAxisSize.min,
fontSize: 13.sp, children: [
height: 1.3.h, Text(
fontWeight:MyFontWeight.regular, // "访问精确地理位置信息权限说明",
color: Colors.black, "位置权限使用说明",
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,
);
},
);
}
} }

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