Commit 0f670f196e55360082d02c4cf3b6c0efba8b0cc3

Authored by wdn127929
1 parent 96319ce5

华为权限同步告知用户使用目的

@@ -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';
@@ -213,23 +214,25 @@ class _EditReserverPageState extends State<EditReserverPage> { @@ -213,23 +214,25 @@ class _EditReserverPageState extends State<EditReserverPage> {
213 } 214 }
214 215
215 _getCallLog() async { 216 _getCallLog() async {
216 - Iterable<CallLogEntry> result = await CallLog.query();  
217 - detailModel.userHistorys = []; 217 + Iterable<CallLogEntry> result = await CallLogUtils.getCallLog(context);
  218 + if (result != null) {
  219 + detailModel.userHistorys = [];
218 220
219 - List<CallLogEntry> object = Utils.removeDuplicates(result.toList()); 221 + List<CallLogEntry> object = Utils.removeDuplicates(result.toList());
220 222
221 - print(object);  
222 - object.forEach((element) {  
223 - UserHistoryEntity userHistoryEntity =  
224 - UserHistoryEntity(null, null, '', '', '', '', '', null);  
225 - userHistoryEntity.rname = element.name ?? '';  
226 - userHistoryEntity.phone = element.number ?? '';  
227 - detailModel.userHistorys.add(userHistoryEntity);  
228 - });  
229 - if (object.length > 0) {  
230 - //有记录  
231 - showPhoneHistory = true;  
232 - setState(() {}); 223 + print(object);
  224 + object.forEach((element) {
  225 + UserHistoryEntity userHistoryEntity =
  226 + UserHistoryEntity(null, null, '', '', '', '', '', null);
  227 + userHistoryEntity.rname = element.name ?? '';
  228 + userHistoryEntity.phone = element.number ?? '';
  229 + detailModel.userHistorys.add(userHistoryEntity);
  230 + });
  231 + if (object.length > 0) {
  232 + //有记录
  233 + showPhoneHistory = true;
  234 + setState(() {});
  235 + }
233 } 236 }
234 } 237 }
235 238
@@ -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 44
@@ -1054,23 +1055,25 @@ class _NoteBookChangeFPageState extends State<NoteBookChangeFPage> { @@ -1054,23 +1055,25 @@ class _NoteBookChangeFPageState extends State<NoteBookChangeFPage> {
1054 } 1055 }
1055 1056
1056 _getCallLog() async { 1057 _getCallLog() async {
1057 - Iterable<CallLogEntry> result = await CallLog.query();  
1058 - _notebookDetailChangeModel.userHistorys = [];  
1059 -  
1060 - List<CallLogEntry> object = Utils.removeDuplicates(result.toList());  
1061 -  
1062 - print(object);  
1063 - object.forEach((element) {  
1064 - UserHistoryEntity userHistoryEntity =  
1065 - UserHistoryEntity(null, null, '', '', '', '', '', null);  
1066 - userHistoryEntity.rname = element.name ?? '';  
1067 - userHistoryEntity.phone = element.number ?? '';  
1068 - _notebookDetailChangeModel.userHistorys.add(userHistoryEntity);  
1069 - });  
1070 - if (object.length > 0) {  
1071 - //有记录  
1072 - showPhoneHistory = true;  
1073 - setState(() {}); 1058 + Iterable<CallLogEntry> result = await CallLogUtils.getCallLog(context);
  1059 + if (result != null) {
  1060 + _notebookDetailChangeModel.userHistorys = [];
  1061 +
  1062 + List<CallLogEntry> object = Utils.removeDuplicates(result.toList());
  1063 +
  1064 + print(object);
  1065 + object.forEach((element) {
  1066 + UserHistoryEntity userHistoryEntity =
  1067 + UserHistoryEntity(null, null, '', '', '', '', '', null);
  1068 + userHistoryEntity.rname = element.name ?? '';
  1069 + userHistoryEntity.phone = element.number ?? '';
  1070 + _notebookDetailChangeModel.userHistorys.add(userHistoryEntity);
  1071 + });
  1072 + if (object.length > 0) {
  1073 + //有记录
  1074 + showPhoneHistory = true;
  1075 + setState(() {});
  1076 + }
1074 } 1077 }
1075 } 1078 }
1076 1079
@@ -267,7 +267,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { @@ -267,7 +267,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
267 if (widget.initialIndex == 0 || 267 if (widget.initialIndex == 0 ||
268 widget.initialIndex == 1 && needRefreshTemp == false) return; 268 widget.initialIndex == 1 && needRefreshTemp == false) return;
269 _initNotification(); 269 _initNotification();
270 - Future.delayed(Duration(milliseconds: 30000), () { 270 + Future.delayed(Duration(minutes: 5), () {
271 //30000 271 //30000
272 ContactModel.getInstance().uploadLocalContact(context); 272 ContactModel.getInstance().uploadLocalContact(context);
273 UserModel usermodel = Provider.of<UserModel>(context, listen: false); 273 UserModel usermodel = Provider.of<UserModel>(context, listen: false);
@@ -54,6 +54,7 @@ import '../../provider/SmsModel.dart'; @@ -54,6 +54,7 @@ import '../../provider/SmsModel.dart';
54 import '../../provider/customer_provider.dart'; 54 import '../../provider/customer_provider.dart';
55 import '../../provider/marketing_center_provider.dart'; 55 import '../../provider/marketing_center_provider.dart';
56 import '../../provider/my_model.dart'; 56 import '../../provider/my_model.dart';
  57 +import '../../utils/call_log_utils.dart';
57 import '../../utils/screen_util.dart'; 58 import '../../utils/screen_util.dart';
58 import '../../widgets/special_text/my_extended_text_selection_controls.dart'; 59 import '../../widgets/special_text/my_extended_text_selection_controls.dart';
59 60
@@ -3912,23 +3913,25 @@ class InvicationPageState extends State<InvicationPage> @@ -3912,23 +3913,25 @@ class InvicationPageState extends State<InvicationPage>
3912 } 3913 }
3913 3914
3914 _getCallLog() async { 3915 _getCallLog() async {
3915 - Iterable<CallLogEntry> result = await CallLog.query();  
3916 - _baseIndoProvider.userHistorys = [];  
3917 -  
3918 - List<CallLogEntry> object = Utils.removeDuplicates(result.toList());  
3919 -  
3920 - print(object);  
3921 - object.forEach((element) {  
3922 - UserHistoryEntity userHistoryEntity =  
3923 - UserHistoryEntity(null, null, '', '', '', '', '', null);  
3924 - userHistoryEntity.rname = element.name ?? '';  
3925 - userHistoryEntity.phone = element.number ?? '';  
3926 - _baseIndoProvider.userHistorys.add(userHistoryEntity);  
3927 - });  
3928 - if (object.length > 0) {  
3929 - //有记录  
3930 - showPhoneHistory = true;  
3931 - setState(() {}); 3916 + Iterable<CallLogEntry> result = await CallLogUtils.getCallLog(context);
  3917 + if (result != null) {
  3918 + _baseIndoProvider.userHistorys = [];
  3919 +
  3920 + List<CallLogEntry> object = Utils.removeDuplicates(result.toList());
  3921 +
  3922 + print(object);
  3923 + object.forEach((element) {
  3924 + UserHistoryEntity userHistoryEntity =
  3925 + UserHistoryEntity(null, null, '', '', '', '', '', null);
  3926 + userHistoryEntity.rname = element.name ?? '';
  3927 + userHistoryEntity.phone = element.number ?? '';
  3928 + _baseIndoProvider.userHistorys.add(userHistoryEntity);
  3929 + });
  3930 + if (object.length > 0) {
  3931 + //有记录
  3932 + showPhoneHistory = true;
  3933 + setState(() {});
  3934 + }
3932 } 3935 }
3933 } 3936 }
3934 3937
@@ -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';
@@ -660,23 +661,25 @@ class TableManagerPageState extends State<TableManagerPage> { @@ -660,23 +661,25 @@ class TableManagerPageState extends State<TableManagerPage> {
660 } 661 }
661 662
662 _getCallLog() async { 663 _getCallLog() async {
663 - Iterable<CallLogEntry> result = await CallLog.query();  
664 - _baseIndoProvider.userHistorys = [];  
665 -  
666 - List<CallLogEntry> object = Utils.removeDuplicates(result.toList());  
667 -  
668 - print(object);  
669 - object.forEach((element) {  
670 - UserHistoryEntity userHistoryEntity =  
671 - UserHistoryEntity(null, null, '', '', '', '', '', null);  
672 - userHistoryEntity.rname = element.name ?? '';  
673 - userHistoryEntity.phone = element.number ?? '';  
674 - _baseIndoProvider.userHistorys.add(userHistoryEntity);  
675 - });  
676 - if (object.length > 0) {  
677 - //有记录  
678 - showPhoneHistory = true;  
679 - setState(() {}); 664 + Iterable<CallLogEntry> result = await CallLogUtils.getCallLog(context);
  665 + if (result != null) {
  666 + _baseIndoProvider.userHistorys = [];
  667 +
  668 + List<CallLogEntry> object = Utils.removeDuplicates(result.toList());
  669 +
  670 + print(object);
  671 + object.forEach((element) {
  672 + UserHistoryEntity userHistoryEntity =
  673 + UserHistoryEntity(null, null, '', '', '', '', '', null);
  674 + userHistoryEntity.rname = element.name ?? '';
  675 + userHistoryEntity.phone = element.number ?? '';
  676 + _baseIndoProvider.userHistorys.add(userHistoryEntity);
  677 + });
  678 + if (object.length > 0) {
  679 + //有记录
  680 + showPhoneHistory = true;
  681 + setState(() {});
  682 + }
680 } 683 }
681 } 684 }
682 685
  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,
@@ -5621,7 +5679,8 @@ class DialogUtil { @@ -5621,7 +5679,8 @@ class DialogUtil {
5621 } 5679 }
5622 5680
5623 //显示消息弹框 5681 //显示消息弹框
5624 - static showMessageDialog(BuildContext context,CollectStoreProvider collectStoreProvider) async { 5682 + static showMessageDialog(
  5683 + BuildContext context, CollectStoreProvider collectStoreProvider) async {
5625 MessageDialogModel messageModel = 5684 MessageDialogModel messageModel =
5626 Provider.of<MessageDialogModel>(context, listen: false); 5685 Provider.of<MessageDialogModel>(context, listen: false);
5627 if (messageModel.messages.isEmpty) return null; 5686 if (messageModel.messages.isEmpty) return null;
@@ -5743,8 +5802,8 @@ class DialogUtil { @@ -5743,8 +5802,8 @@ class DialogUtil {
5743 ) 5802 )
5744 : ListView.builder( 5803 : ListView.builder(
5745 itemBuilder: (context, index) { 5804 itemBuilder: (context, index) {
5746 - return MessageDialogItemF(  
5747 - model.messages[index],collectStoreProvider); 5805 + return MessageDialogItemF(model.messages[index],
  5806 + collectStoreProvider);
5748 }, 5807 },
5749 itemCount: model.messages.length, 5808 itemCount: model.messages.length,
5750 shrinkWrap: true) 5809 shrinkWrap: true)
  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);
@@ -56,8 +78,13 @@ Future<PermissionStatus> contactPermissionStatus() async { @@ -56,8 +78,13 @@ Future<PermissionStatus> contactPermissionStatus() async {
56 return permissionStatus; 78 return permissionStatus;
57 } 79 }
58 80
59 -  
60 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 + }
61 final permissions = await [Permission.contacts].request(); 88 final permissions = await [Permission.contacts].request();
62 if (permissions[Permission.contacts] == PermissionStatus.granted) { 89 if (permissions[Permission.contacts] == PermissionStatus.granted) {
63 return true; 90 return true;