Commit b6a5186e6cc835b41fb596ace320256738c099a7

Authored by wdn127929
2 parents 5cf7fb7c b40782f2

合并 5.1.5.6分支内容: 权限请求时同步提醒用户使用目的

@@ -16,6 +16,9 @@ class App { @@ -16,6 +16,9 @@ class App {
16 // static GetIt getIt = GetIt.instance; 16 // static GetIt getIt = GetIt.instance;
17 static bool isInstallWx = false; 17 static bool isInstallWx = false;
18 18
  19 + static final GlobalKey<NavigatorState> navigatorKey =
  20 + new GlobalKey<NavigatorState>();
  21 +
19 static initSp() async { 22 static initSp() async {
20 sp = await SharedPreferences.getInstance(); 23 sp = await SharedPreferences.getInstance();
21 } 24 }
@@ -142,6 +142,7 @@ Future<void> main() async { @@ -142,6 +142,7 @@ Future<void> main() async {
142 }); 142 });
143 } 143 }
144 144
  145 +
145 class MyApp extends StatefulWidget { 146 class MyApp extends StatefulWidget {
146 @override 147 @override
147 State<StatefulWidget> createState() { 148 State<StatefulWidget> createState() {
@@ -250,6 +251,7 @@ class MyAppState extends State<MyApp> { @@ -250,6 +251,7 @@ class MyAppState extends State<MyApp> {
250 return MaterialApp( 251 return MaterialApp(
251 debugShowCheckedModeBanner: false, 252 debugShowCheckedModeBanner: false,
252 title: '周到安排商家', 253 title: '周到安排商家',
  254 + navigatorKey: App.navigatorKey,
253 // navigatorKey: App.getIt<NavigateService>().key, 255 // navigatorKey: App.getIt<NavigateService>().key,
254 //国际化 256 //国际化
255 localizationsDelegates: const [ 257 localizationsDelegates: const [
@@ -25,6 +25,7 @@ import 'package:permission_handler/permission_handler.dart'; @@ -25,6 +25,7 @@ import 'package:permission_handler/permission_handler.dart';
25 import 'package:provider/provider.dart'; 25 import 'package:provider/provider.dart';
26 26
27 import '../../models/user_history_entity.dart'; 27 import '../../models/user_history_entity.dart';
  28 +import '../../utils/call_log_utils.dart';
28 import '../../utils/screen_util.dart'; 29 import '../../utils/screen_util.dart';
29 import '../../widgets/MyDivider.dart'; 30 import '../../widgets/MyDivider.dart';
30 import '../../widgets/special_text/my_extended_text_selection_controls.dart'; 31 import '../../widgets/special_text/my_extended_text_selection_controls.dart';
@@ -214,13 +215,13 @@ class _EditReserverPageState extends State<EditReserverPage> { @@ -214,13 +215,13 @@ class _EditReserverPageState extends State<EditReserverPage> {
214 } 215 }
215 216
216 _getCallLog() async { 217 _getCallLog() async {
217 - try {  
218 - Iterable<CallLogEntry> result = await CallLog.query();  
219 - List<Picker.PickerItem<dynamic>> data = []; 218 + List<Picker.PickerItem<dynamic>> data = [];
220 219
221 - List<CallLogEntry> object = Utils.removeDuplicates(result.toList()); 220 + Iterable<CallLogEntry> result = await CallLogUtils.getCallLog(context);
  221 + if (result != null) {
  222 + detailModel.userHistorys = [];
222 223
223 - print(object); 224 + List<CallLogEntry> object = Utils.removeDuplicates(result.toList());
224 225
225 detailModel.userHistorys = []; 226 detailModel.userHistorys = [];
226 showPhoneHistory = false; 227 showPhoneHistory = false;
@@ -300,7 +301,7 @@ class _EditReserverPageState extends State<EditReserverPage> { @@ -300,7 +301,7 @@ class _EditReserverPageState extends State<EditReserverPage> {
300 } else { 301 } else {
301 Utils.showToast('暂无通话记录!'); 302 Utils.showToast('暂无通话记录!');
302 } 303 }
303 - } catch (e) {} 304 + }
304 } 305 }
305 306
306 _byValueToReqeust(int index) { 307 _byValueToReqeust(int index) {
@@ -38,6 +38,7 @@ import 'package:one_key/models/table_list.dart' as t; @@ -38,6 +38,7 @@ import 'package:one_key/models/table_list.dart' as t;
38 import 'dart:convert' as convert; 38 import 'dart:convert' as convert;
39 import 'package:easy_contact_picker/easy_contact_picker.dart'; 39 import 'package:easy_contact_picker/easy_contact_picker.dart';
40 import '../../models/user_history_entity.dart'; 40 import '../../models/user_history_entity.dart';
  41 +import '../../utils/call_log_utils.dart';
41 import '../../utils/screen_util.dart'; 42 import '../../utils/screen_util.dart';
42 import '../../widgets/special_text/my_extended_text_selection_controls.dart'; 43 import '../../widgets/special_text/my_extended_text_selection_controls.dart';
43 import 'package:flutter_picker/flutter_picker.dart' as Picker; 44 import 'package:flutter_picker/flutter_picker.dart' as Picker;
@@ -1075,9 +1076,11 @@ class _NoteBookChangeFPageState extends State<NoteBookChangeFPage> { @@ -1075,9 +1076,11 @@ class _NoteBookChangeFPageState extends State<NoteBookChangeFPage> {
1075 // } 1076 // }
1076 // } 1077 // }
1077 _getCallLog() async { 1078 _getCallLog() async {
1078 - try {  
1079 - Iterable<CallLogEntry> result = await CallLog.query();  
1080 - List<Picker.PickerItem<dynamic>> data = []; 1079 + List<Picker.PickerItem<dynamic>> data = [];
  1080 +
  1081 + Iterable<CallLogEntry> result = await CallLogUtils.getCallLog(context);
  1082 + if (result != null) {
  1083 + _notebookDetailChangeModel.userHistorys = [];
1081 1084
1082 List<CallLogEntry> object = Utils.removeDuplicates(result.toList()); 1085 List<CallLogEntry> object = Utils.removeDuplicates(result.toList());
1083 1086
@@ -1161,9 +1164,6 @@ class _NoteBookChangeFPageState extends State<NoteBookChangeFPage> { @@ -1161,9 +1164,6 @@ class _NoteBookChangeFPageState extends State<NoteBookChangeFPage> {
1161 } else { 1164 } else {
1162 Utils.showToast('暂无通话记录!'); 1165 Utils.showToast('暂无通话记录!');
1163 } 1166 }
1164 - } catch (e) {  
1165 - print(e);  
1166 -  
1167 } 1167 }
1168 } 1168 }
1169 1169
@@ -3,6 +3,7 @@ import 'dart:convert'; @@ -3,6 +3,7 @@ import 'dart:convert';
3 import 'dart:io'; 3 import 'dart:io';
4 import 'package:cached_network_image/cached_network_image.dart'; 4 import 'package:cached_network_image/cached_network_image.dart';
5 import 'package:common_utils/common_utils.dart'; 5 import 'package:common_utils/common_utils.dart';
  6 +import 'package:device_info/device_info.dart';
6 import 'package:flutter/cupertino.dart'; 7 import 'package:flutter/cupertino.dart';
7 import 'package:flutter/material.dart'; 8 import 'package:flutter/material.dart';
8 import 'package:flutter/services.dart'; 9 import 'package:flutter/services.dart';
@@ -267,7 +268,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { @@ -267,7 +268,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
267 if (widget.initialIndex == 0 || 268 if (widget.initialIndex == 0 ||
268 widget.initialIndex == 1 && needRefreshTemp == false) return; 269 widget.initialIndex == 1 && needRefreshTemp == false) return;
269 _initNotification(); 270 _initNotification();
270 - Future.delayed(Duration(milliseconds: 30000), () { 271 + Future.delayed(Duration(minutes: 5), () {
271 //30000 272 //30000
272 ContactModel.getInstance().uploadLocalContact(context); 273 ContactModel.getInstance().uploadLocalContact(context);
273 UserModel usermodel = Provider.of<UserModel>(context, listen: false); 274 UserModel usermodel = Provider.of<UserModel>(context, listen: false);
@@ -943,7 +944,22 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { @@ -943,7 +944,22 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
943 } 944 }
944 945
945 //初始化信鸽推送 946 //初始化信鸽推送
946 - initPlatformState() { 947 + initPlatformState() async {
  948 + //安卓弹窗提示使用通知权限目的,仅提示一次
  949 +
  950 + //全局提示权限使用目的
  951 + // if (Platform.isAndroid) {
  952 + // DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  953 + // AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
  954 + // if (androidInfo.manufacturer == 'HUAWEI') {
  955 + // if (!(App.sp.getBool("h_notification") ?? false)) {
  956 + // DialogUtil.showAuthorityDestination(context, 'h_notification',
  957 + // '通知权限使用说明', '在客户预订以及店内营销需要的时候,给您发送通知消息。');
  958 + // }
  959 + // }
  960 + // }
  961 + // App.sp.setBool("h_notification", true);
  962 +
947 /// 开启DEBUG 963 /// 开启DEBUG
948 XgFlutterPlugin().setEnableDebug(false); 964 XgFlutterPlugin().setEnableDebug(false);
949 965
@@ -57,6 +57,7 @@ import '../../provider/SmsModel.dart'; @@ -57,6 +57,7 @@ import '../../provider/SmsModel.dart';
57 import '../../provider/customer_provider.dart'; 57 import '../../provider/customer_provider.dart';
58 import '../../provider/marketing_center_provider.dart'; 58 import '../../provider/marketing_center_provider.dart';
59 import '../../provider/my_model.dart'; 59 import '../../provider/my_model.dart';
  60 +import '../../utils/call_log_utils.dart';
60 import '../../utils/screen_util.dart'; 61 import '../../utils/screen_util.dart';
61 import '../../widgets/special_text/my_extended_text_selection_controls.dart'; 62 import '../../widgets/special_text/my_extended_text_selection_controls.dart';
62 import 'package:flutter_picker/flutter_picker.dart' as Picker; 63 import 'package:flutter_picker/flutter_picker.dart' as Picker;
@@ -3930,9 +3931,11 @@ class InvicationPageState extends State<InvicationPage> @@ -3930,9 +3931,11 @@ class InvicationPageState extends State<InvicationPage>
3930 } 3931 }
3931 3932
3932 _getCallLog() async { 3933 _getCallLog() async {
3933 - try {  
3934 - Iterable<CallLogEntry> result = await CallLog.query();  
3935 - List<Picker.PickerItem<dynamic>> data = []; 3934 + List<Picker.PickerItem<dynamic>> data = [];
  3935 +
  3936 + Iterable<CallLogEntry> result = await CallLogUtils.getCallLog(context);
  3937 + if (result != null) {
  3938 + _baseIndoProvider.userHistorys = [];
3936 3939
3937 List<CallLogEntry> object = Utils.removeDuplicates(result.toList()); 3940 List<CallLogEntry> object = Utils.removeDuplicates(result.toList());
3938 3941
@@ -4025,7 +4028,7 @@ class InvicationPageState extends State<InvicationPage> @@ -4025,7 +4028,7 @@ class InvicationPageState extends State<InvicationPage>
4025 } else { 4028 } else {
4026 Utils.showToast('暂无通话记录!'); 4029 Utils.showToast('暂无通话记录!');
4027 } 4030 }
4028 - } catch (e) {} 4031 + }
4029 } 4032 }
4030 4033
4031 _openAddressBook() async { 4034 _openAddressBook() async {
@@ -59,6 +59,7 @@ import '../../provider/SmsModel.dart'; @@ -59,6 +59,7 @@ import '../../provider/SmsModel.dart';
59 import '../../provider/marketing_center_provider.dart'; 59 import '../../provider/marketing_center_provider.dart';
60 import '../../provider/remark_manager_model.dart'; 60 import '../../provider/remark_manager_model.dart';
61 import '../../provider/store_base_info_provider.dart'; 61 import '../../provider/store_base_info_provider.dart';
  62 +import '../../utils/call_log_utils.dart';
62 import '../../utils/screen_util.dart'; 63 import '../../utils/screen_util.dart';
63 import '../../widgets/loading.dart'; 64 import '../../widgets/loading.dart';
64 import '../../widgets/special_text/my_extended_text_selection_controls.dart'; 65 import '../../widgets/special_text/my_extended_text_selection_controls.dart';
@@ -682,10 +683,15 @@ class TableManagerPageState extends State<TableManagerPage> { @@ -682,10 +683,15 @@ class TableManagerPageState extends State<TableManagerPage> {
682 // } 683 // }
683 684
684 _getCallLog() async { 685 _getCallLog() async {
685 - try {  
686 - Iterable<CallLogEntry> result = await CallLog.query(); 686 +
  687 +
687 List<Picker.PickerItem<dynamic>> data = []; 688 List<Picker.PickerItem<dynamic>> data = [];
688 689
  690 + Iterable<CallLogEntry> result = await CallLogUtils.getCallLog(context);
  691 + if (result != null) {
  692 + _baseIndoProvider.userHistorys = [];
  693 +
  694 +
689 List<CallLogEntry> object = Utils.removeDuplicates(result.toList()); 695 List<CallLogEntry> object = Utils.removeDuplicates(result.toList());
690 696
691 print(object); 697 print(object);
@@ -768,7 +774,7 @@ class TableManagerPageState extends State<TableManagerPage> { @@ -768,7 +774,7 @@ class TableManagerPageState extends State<TableManagerPage> {
768 } else { 774 } else {
769 Utils.showToast('暂无通话记录!'); 775 Utils.showToast('暂无通话记录!');
770 } 776 }
771 - } catch (e) {} 777 + }
772 } 778 }
773 779
774 _byValueToReqeust(int index) { 780 _byValueToReqeust(int index) {
@@ -813,6 +819,7 @@ class TableManagerPageState extends State<TableManagerPage> { @@ -813,6 +819,7 @@ class TableManagerPageState extends State<TableManagerPage> {
813 _phoneNode.unfocus(); 819 _phoneNode.unfocus();
814 _baseIndoProvider.userHistorys.clear(); 820 _baseIndoProvider.userHistorys.clear();
815 }); 821 });
  822 +
816 } 823 }
817 824
818 _getContactData() async { 825 _getContactData() async {
  1 +import 'dart:io';
  2 +
  3 +import 'package:call_log/call_log.dart';
  4 +import 'package:flutter/material.dart';
  5 +import 'package:one_key/utils/dialog_util.dart';
  6 +import 'package:permission_handler/permission_handler.dart';
  7 +
  8 +import 'misc.dart';
  9 +
  10 +class CallLogUtils {
  11 + static Future<Iterable<CallLogEntry>> getCallLog(context) async {
  12 + try {
  13 + if (!(await checkPermission(Permission.phone))) {
  14 + String title = '通话记录和电话';
  15 + PermissionStatus status = await permissionStatus(Permission.phone);
  16 + if (status == PermissionStatus.permanentlyDenied) {
  17 + //用户选择不在弹出权限提示框
  18 + print('never');
  19 + // Navigator.pop(context);
  20 + DialogUtil.openAlertDialog(context, '未获得${title}权限',
  21 + "请在手机的权限管理里,将${title}权限开启", '去设置', 340.0, onTap: () {
  22 + openSetting();
  23 + Navigator.pop(context, '');
  24 + });
  25 + } else {
  26 + // 申请权限
  27 + bool canPhone = await checkPermission(Permission.phone);
  28 + if (canPhone) {
  29 + try {
  30 + //全局提示权限使用目的
  31 + if (Platform.isAndroid) {
  32 + DialogUtil.showAuthorityDestination(context, 'h_call',
  33 + '通话记录和电话权限使用说明', '直接从通话记录中获得客户电话号码,快速录入预订信息。');
  34 + }
  35 +
  36 + Iterable<CallLogEntry> result = await CallLog.query();
  37 + return result;
  38 + } catch (e) {
  39 + print(e);
  40 + }
  41 + } else {
  42 + // Navigator.pop(context);
  43 + //拒绝通讯录权限 , 苹果拒绝权限后,不再提示权限框,进入此处
  44 + DialogUtil.openAlertDialog(context, '未获得${title}权限',
  45 + "请在手机的权限管理里,将${title}权限开启。", '去设置', 340.0, onTap: () {
  46 + openSetting();
  47 + Navigator.pop(context, '');
  48 + });
  49 + }
  50 + }
  51 + } else {
  52 + try {
  53 + //全局提示权限使用目的
  54 + if (Platform.isAndroid) {
  55 + DialogUtil.showAuthorityDestination(context, 'h_call',
  56 + '通话记录和电话权限使用说明', '直接从通话记录中获得客户电话号码,快速录入预订信息。');
  57 + }
  58 +
  59 + Iterable<CallLogEntry> result = await CallLog.query();
  60 + return result;
  61 + } catch (e) {
  62 + print(e);
  63 + }
  64 + }
  65 + } catch (e) {
  66 + print(e);
  67 + return null;
  68 + }
  69 + }
  70 +}
@@ -59,6 +59,64 @@ typedef ClickCallback = void Function(String value); @@ -59,6 +59,64 @@ typedef ClickCallback = void Function(String value);
59 // }; 59 // };
60 60
61 class DialogUtil { 61 class DialogUtil {
  62 + static showAuthorityDestination(
  63 + BuildContext context, String name, String title, String subTitle) {
  64 + Future.delayed(const Duration(seconds: 5), () {
  65 + Navigator.of(context).pop(true);
  66 + });
  67 + return showDialog(
  68 + context: context,
  69 + barrierDismissible: true,
  70 + anchorPoint:Offset(0,0),
  71 +
  72 + builder: (BuildContext context) {
  73 + return StatefulBuilder(builder: (context, state) {
  74 + // locationState = state;
  75 + return Material(
  76 + color: Colors.transparent,
  77 + child: Column(mainAxisSize: MainAxisSize.min, children: [
  78 + VEmptyView(40),
  79 + Container(
  80 + // width: double.infinity,
  81 +
  82 + margin: EdgeInsets.symmetric(horizontal: w(10)),
  83 + padding: EdgeInsets.symmetric(
  84 + horizontal: w(20), vertical: w(12)),
  85 + decoration: BoxDecoration(
  86 + color: MyColours.color_ffffff,
  87 + borderRadius: BorderRadius.circular(
  88 + r(5),
  89 + )),
  90 + child: Row(children: <Widget>[
  91 + Image.asset(
  92 + Utils.getImgPath(
  93 + '$name',
  94 + ),
  95 + width: w(30)),
  96 + HEmptyView(68),
  97 + Expanded(
  98 + child: Column(
  99 + crossAxisAlignment: CrossAxisAlignment.start,
  100 + children: [
  101 + Text('$title',
  102 + style: TextStyle(
  103 + fontSize: font(16),
  104 + fontWeight: FontWeight.bold,
  105 + color: MyColours.color_E6000000)),
  106 + VEmptyView(20),
  107 + Text('$subTitle',
  108 + style: TextStyle(
  109 + fontSize: font(16),
  110 + color: MyColours.color_26000000))
  111 + ])),
  112 + ]))
  113 + ]));
  114 + });
  115 + });
  116 +
  117 + ;
  118 + }
  119 +
62 //模块快过期提醒 120 //模块快过期提醒
63 static showSellerVersionEdateDialog(BuildContext context, 121 static showSellerVersionEdateDialog(BuildContext context,
64 List<SellerVersionSunModel> showData, CustomCallBack callback, 122 List<SellerVersionSunModel> showData, CustomCallBack callback,
  1 +import 'dart:io';
  2 +
  3 +import 'package:flutter/material.dart';
1 import 'package:flutter/services.dart'; 4 import 'package:flutter/services.dart';
  5 +import 'package:one_key/utils/dialog_util.dart';
2 import 'package:permission_handler/permission_handler.dart'; 6 import 'package:permission_handler/permission_handler.dart';
3 7
  8 +import '../app.dart';
  9 +
4 Future<bool> checkPermissionStorage() async { 10 Future<bool> checkPermissionStorage() async {
5 var status = await Permission.storage.status; 11 var status = await Permission.storage.status;
6 if (!status.isGranted) { 12 if (!status.isGranted) {
@@ -33,6 +39,22 @@ Future<bool> checkPermission(Permission permissionGroup) async { @@ -33,6 +39,22 @@ Future<bool> checkPermission(Permission permissionGroup) async {
33 } 39 }
34 40
35 Future<bool> requestPermission(Permission permissionGroup) async { 41 Future<bool> requestPermission(Permission permissionGroup) async {
  42 + //全局提示权限使用目的
  43 + if (Platform.isAndroid) {
  44 + //全局提示权限使用目的
  45 + BuildContext context = App.navigatorKey.currentState.overlay.context;
  46 + if (permissionGroup == Permission.storage) {
  47 + DialogUtil.showAuthorityDestination(
  48 + context, 'h_storage', '存储权限使用说明', '用于读取相册照片上传店铺门头照,包间照片等。');
  49 + } else if (permissionGroup == Permission.camera) {
  50 + DialogUtil.showAuthorityDestination(
  51 + context, 'h_camera', '相机权限使用说明', '用于上传店铺门头照,包间照片等。');
  52 + } else if (permissionGroup == Permission.location) {
  53 + DialogUtil.showAuthorityDestination(
  54 + context, 'h_location', '位置权限使用说明', '用于创建店铺时,获取店铺在地图上的位置,方便客户导航到咱们店铺');
  55 + }
  56 + }
  57 +
36 final permissions = await [permissionGroup].request(); 58 final permissions = await [permissionGroup].request();
37 if (await permissionGroup.request().isGranted) { 59 if (await permissionGroup.request().isGranted) {
38 print(true); 60 print(true);
@@ -57,6 +79,12 @@ Future<PermissionStatus> contactPermissionStatus() async { @@ -57,6 +79,12 @@ Future<PermissionStatus> contactPermissionStatus() async {
57 } 79 }
58 80
59 Future<bool> requestContactPermission() async { 81 Future<bool> requestContactPermission() async {
  82 + if (Platform.isAndroid) {
  83 + //全局提示权限使用目的
  84 + BuildContext context = App.navigatorKey.currentState.overlay.context;
  85 + DialogUtil.showAuthorityDestination(
  86 + context, 'h_contant', '通讯录权限使用说明', '直接从通讯录获得客户电话号码,快速录入预订信息。');
  87 + }
60 final permissions = await [Permission.contacts].request(); 88 final permissions = await [Permission.contacts].request();
61 if (permissions[Permission.contacts] == PermissionStatus.granted) { 89 if (permissions[Permission.contacts] == PermissionStatus.granted) {
62 return true; 90 return true;