From 38ed896fddd03d3f9eee4b8f6e31bfc590207fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyanghuaxuan=E2=80=9D?= <“646903573@qq.com”> Date: Wed, 14 Apr 2021 18:25:50 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=8F=98=E6=9B=B4=E6=8E=88=E6=9D=83=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/android/app/build.gradle | 8 +- .../MainActivity.java | 10 +- .../notification_setting_dialog.dart | 197 +++++++++++++++++- lib/pages/home_page/home_page.dart | 2 +- 4 files changed, 201 insertions(+), 16 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 80ff64e..3a69364 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -20,7 +20,7 @@ if (flutterVersionCode == null) { def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { - flutterVersionName = '1.0' + flutterVersionName = '1.6.0' } // 获取当前时间(年月日) @@ -45,15 +45,15 @@ android { applicationId "cn.zhios.zhiying" minSdkVersion 21 targetSdkVersion 28 - versionCode 1 - versionName "1.0" + versionCode 1618056485 + versionName "10.6.0" aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" ndk { //选择要添加的对应cpu类型的.so库。 - abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a' + //abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a' // abiFilters 'armeabi-v7a','x86_64' } } diff --git a/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java b/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java index 760a32e..6256890 100644 --- a/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java +++ b/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java @@ -158,9 +158,9 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN public Map getSetting() { Map map = new HashMap(); ///测试 - map.put("domain", "http://inapi.izhyin.cn/");//"http://120.76.175.204:8989");http://47.114.51.254:80 http://inapi.izhyin.cn/ - map.put("master_id", "123456"); - map.put("secret_key", "123456"); +// map.put("domain", "http://inapi.izhyin.cn/");//"http://120.76.175.204:8989");http://47.114.51.254:80 http://inapi.izhyin.cn/ +// map.put("master_id", "123456"); +// map.put("secret_key", "123456"); ///正式 // map.put("domain", "http://api.zhios.cn/");//45678910,api.zhios.cn84198689 @@ -173,6 +173,10 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN // map.put("secret_key", "123456"); // map.put("token", "123465"); + + map.put("domain", "http://api.shengder.com/");//"http://120.76.175.204:8989");http://47.114.51.254:80 http://inapi.izhyin.cn/ + map.put("master_id", "98130614"); + map.put("secret_key", "123456"); return map; } diff --git a/lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart b/lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart index 04bc700..815cc42 100644 --- a/lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart +++ b/lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart @@ -119,14 +119,7 @@ class NotificationSettingDialog extends StatelessWidget { ), GestureDetector( onTap: () async { - // 检查并请求权限 - PermissionStatus status = await Permission.notification.request(); - if (status == PermissionStatus.denied) { - await openAppSettings(); - } else if (status != PermissionStatus.granted) { - status = await Permission.notification.request(); - } - Navigator.pop(context); + Navigator.pop(context, true); return true; }, child: Container( @@ -202,3 +195,191 @@ class NotificationSettingDialog extends StatelessWidget { ); } } + +class NotificationSettingDialogNew extends StatelessWidget { + List permissModels; + + NotificationSettingDialogNew(this.permissModels, {Key key}) : super(key: key); + + static Future show(BuildContext context, {List permissModels}) async { + List newPermissModels; + if (permissModels == null) { + newPermissModels = List(); + if (!await Permission.storage.isGranted) { + newPermissModels.add(PermissModel( + permissType: PermissType.storage, + title: "存储权限", + subTitle: "用于缓存数据,保存图片到相册", + iconUrl: "https://alipic.lanhuapp.com/SketchPng7acf1ec3d1c3c98ba9b58d52a5d49ff3404a0b3f131100695dcd479c8dfa215b")); + } + + if (!await Permission.notification.isGranted) { + newPermissModels.add(PermissModel( + permissType: PermissType.notification, + title: "通知权限", + subTitle: "用于及时告知优惠动态", + iconUrl: "https://alipic.lanhuapp.com/SketchPnga11a94a0c38949016e0fced74d683c08eaa1f58366cba616a40e51a9ebbe7146")); + } + } else { + newPermissModels = permissModels; + } + if (newPermissModels.length == 0) { + return; + } + await showCupertinoDialog(context: context, builder: (_) => NotificationSettingDialogNew(newPermissModels)); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.transparent, + body: Container( + width: double.infinity, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + width: 280, + padding: EdgeInsets.all(20), + // height: 382, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + ), + child: Column( + children: [ + Text( + "申请获取权限", + style: TextStyle( + fontSize: 15, + fontWeight: FontWeight.bold, + color: HexColor.fromHex('#FF4242'), + ), + ), + SizedBox( + height: 10, + ), + Text( + " \t\t\t\t\t为了保证您可以正常使用APP, 更好地为您提供服务, 我们需要向您申请获得如下权限", + style: TextStyle(fontSize: 13, color: HexColor.fromHex("#FF666666")), + ), + SizedBox( + height: 10, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: permissModels.map((e) => _createItem(e)).toList() ?? [], + ), + SizedBox( + height: 20, + ), + GestureDetector( + onTap: () async { + for (var item in permissModels) { + if (item.permissType == PermissType.notification) { + if (!await Permission.notification.isGranted) { + await Permission.notification.request(); + if (await Permission.notification.isDenied) { + if (Platform.isAndroid) { + await NativeUtil.openAppSettings(); + } else { + openAppSettings(); + } + } + } + } else if (item.permissType == PermissType.storage) { + if (!await Permission.storage.isGranted) { + await Permission.storage.request(); + } + if (await Permission.storage.isPermanentlyDenied) { + openAppSettings(); + } + } + } + Navigator.pop(context, true); + }, + child: Container( + margin: EdgeInsets.only(top: 10, bottom: 10), + height: 38, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + gradient: + LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [HexColor.fromHex("#FFFF5632"), HexColor.fromHex("#FFFF4242")])), + child: Center( + child: Text( + "确认授权", + style: TextStyle(color: Colors.white, fontSize: 13), + ))), + ) + ], + ), + ), + GestureDetector( + onTap: () { + Navigator.pop(context, false); + }, + child: Container(width: 30, height: 30, margin: EdgeInsets.only(top: 10), child: CloseButton(color: HexColor.fromHex("#FFFFFF")))) + ], + ), + ), + ); + } + + Widget _createItem(PermissModel itemModel) { + return Container( + decoration: BoxDecoration(color: HexColor.fromHex("#FFFAFAFA"), borderRadius: BorderRadius.circular(8)), + margin: EdgeInsets.only(top: 8), + child: Padding( + padding: EdgeInsets.only(left: 8, right: 8, top: 4, bottom: 4), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + margin: EdgeInsets.only(right: 6, top: 2), + width: 27, + height: 27, + child: CachedNetworkImage( + imageUrl: itemModel?.iconUrl ?? '', + )), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + itemModel?.title ?? '', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, + color: HexColor.fromHex('#333333'), + ), + ), + Text( + itemModel?.subTitle ?? '', + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.normal, + color: HexColor.fromHex('#999999'), + ), + ), + ], + ), + ) + ], + ), + ), + ); + } +} + +class PermissModel { + String iconUrl; + String title; + String subTitle; + PermissType permissType; + + PermissModel({this.iconUrl, this.title, this.subTitle, this.permissType}); +} + +enum PermissType { notification, storage } diff --git a/lib/pages/home_page/home_page.dart b/lib/pages/home_page/home_page.dart index 2502602..522144f 100644 --- a/lib/pages/home_page/home_page.dart +++ b/lib/pages/home_page/home_page.dart @@ -366,7 +366,7 @@ class _HomePageState extends LifeState with WidgetsBindingObserver, Ti // 通知弹窗 if (!await Permission.notification.isGranted || !await Permission.storage.isGranted) { - await NotificationSettingDialog.show(context); + await NotificationSettingDialogNew.show(context); } // 活动弹窗