Browse Source

适配更改

dev
wurong 1 year ago
parent
commit
b6c99666cc
  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/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';

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_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,8 +146,10 @@ class UnionPageState extends State<UnionPage>
if (!powerFlag) {
if (await Permission.locationWhenInUse.status.isGranted) {
startLocation();
} else
} else {
_isShowLocalTips = true;
loadFinish(showLoading: false);
}
}
}
}
@ -185,120 +206,134 @@ class UnionPageState extends State<UnionPage>
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: <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(
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),
],
),
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;
});
}),
)
],
),
);
}

217
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<bool> startLocation(context, Function(BaiduLocation result) locationCallback) async {
aMapFlutterLocation.prepareLoc(initAndroidOptions().getMap(), initIOSOptions().getMap());
if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) {
enableLocation(context);
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;
}
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: <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: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,
);
},
);
}
}

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