Sfoglia il codice sorgente

1.增加各种权限申请前先提示信息、首页通知权限每启动5次检测一次

tags/0.0.14+4
“yanghuaxuan” 3 anni fa
parent
commit
eea6f5bdae
6 ha cambiato i file con 72 aggiunte e 38 eliminazioni
  1. +29
    -16
      lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart
  2. +9
    -3
      lib/pages/home_page/home_page.dart
  3. +1
    -1
      lib/utils/contants.dart
  4. +22
    -15
      lib/widgets/share/share_alert.dart
  5. +8
    -1
      lib/widgets/share/share_alert_select.dart
  6. +3
    -2
      lib/zhiying_base_widget.dart

+ 29
- 16
lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart Vedi File

@@ -201,24 +201,34 @@ class NotificationSettingDialogNew extends StatelessWidget {

NotificationSettingDialogNew(this.permissModels, {Key key}) : super(key: key);

static PermissModel storagePermissModel = PermissModel(
permissType: PermissType.storage,
title: "存储权限",
subTitle: "用于分享照片、保存图片到相册",
iconUrl: "https://alipic.lanhuapp.com/SketchPng7acf1ec3d1c3c98ba9b58d52a5d49ff3404a0b3f131100695dcd479c8dfa215b");

static PermissModel notificationPermissModel = PermissModel(
permissType: PermissType.notification,
title: "通知权限",
subTitle: "用于及时告知优惠动态",
iconUrl: "https://alipic.lanhuapp.com/SketchPnga11a94a0c38949016e0fced74d683c08eaa1f58366cba616a40e51a9ebbe7146");

static PermissModel locationPermissModel = PermissModel(
permissType: PermissType.location,
title: "定位权限",
subTitle: "用于定位当前位置推荐附的优惠动态",
iconUrl: "https://alipic.lanhuapp.com/SketchPng409f144b2042e81840e20c2d528b3f50994869e3f22b5d7d2b8a47abcdb72953");

static Future show(BuildContext context, {List<PermissModel> permissModels}) async {
List<PermissModel> 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"));
newPermissModels.add(storagePermissModel);
}

if (!await Permission.notification.isGranted) {
newPermissModels.add(PermissModel(
permissType: PermissType.notification,
title: "通知权限",
subTitle: "用于及时告知优惠动态",
iconUrl: "https://alipic.lanhuapp.com/SketchPnga11a94a0c38949016e0fced74d683c08eaa1f58366cba616a40e51a9ebbe7146"));
newPermissModels.add(notificationPermissModel);
}
} else {
newPermissModels = permissModels;
@@ -282,7 +292,7 @@ class NotificationSettingDialogNew extends StatelessWidget {
await Permission.notification.request();
if (await Permission.notification.isDenied) {
if (Platform.isAndroid) {
await NativeUtil.openAppSettings();
await NativeUtil.openAppSettings();
} else {
openAppSettings();
}
@@ -295,6 +305,8 @@ class NotificationSettingDialogNew extends StatelessWidget {
if (await Permission.storage.isPermanentlyDenied) {
openAppSettings();
}
} else if (item?.permissType == PermissType.location) {
await Permission.location.request();
}
}
Navigator.pop(context, true);
@@ -316,10 +328,11 @@ class NotificationSettingDialogNew extends StatelessWidget {
),
),
GestureDetector(
onTap: () {
Navigator.pop(context, false);
},
child: Container(width: 30, height: 30, margin: EdgeInsets.only(top: 10), child: CloseButton(color: HexColor.fromHex("#FFFFFF"))))
onTap: () {
Navigator.pop(context, false);
},
child: Container(alignment: Alignment.center, margin: EdgeInsets.only(top: 10), child: CloseButton(color: HexColor.fromHex("#FFFFFF"))),
)
],
),
),
@@ -382,4 +395,4 @@ class PermissModel {
PermissModel({this.iconUrl, this.title, this.subTitle, this.permissType});
}

enum PermissType { notification, storage }
enum PermissType { notification, storage, location }

+ 9
- 3
lib/pages/home_page/home_page.dart Vedi File

@@ -358,10 +358,16 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
Future _showPolicy() async {
await Future.delayed(Duration(milliseconds: 1000), () async {
// 通知弹窗

if (!await Permission.notification.isGranted || !await Permission.storage.isGranted) {
await NotificationSettingDialogNew.show(context);
///每打开5次检查一次权限
String showNotiPermissionTime = await SharedPreferencesUtil.getStringValue(Constants.showNotiPermissionTime, defaultVal: "5");
int timer = int.tryParse(showNotiPermissionTime) ?? 0;
if (timer % 5 == 0) {
if (!await Permission.notification.isGranted || !await Permission.storage.isGranted) {
await NotificationSettingDialogNew.show(context);
}
}
timer++;
SharedPreferencesUtil.setStringValue(Constants.showNotiPermissionTime, timer.toString());

// 活动弹窗
await AdvertisingDialog.show(context);


+ 1
- 1
lib/utils/contants.dart Vedi File

@@ -23,7 +23,7 @@ class Constants {
static String isShowPolicy = "is_show_policy";

///推送权限弹窗
static String isShowNotiPermission = "isShowNotiPermission";
static String showNotiPermissionTime = "showNotiPermissionTime";

//==============================弹窗===================================end



+ 22
- 15
lib/widgets/share/share_alert.dart Vedi File

@@ -12,6 +12,7 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:share_extend/share_extend.dart';
import 'package:sharesdk_plugin/sharesdk_plugin.dart';
import 'package:zhiying_base_widget/dialog/global_dialog/intellect_search_goods_dialog/intellect_create.dart';
import 'package:zhiying_base_widget/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart';
import 'package:zhiying_base_widget/dialog/loading/loading.dart';
import 'package:zhiying_base_widget/utils/image_download_util/image_download_util.dart';
import 'package:zhiying_base_widget/widgets/share/models/share_alert_model.dart';
@@ -38,6 +39,7 @@ class _ShareAlertState extends State<ShareAlert> {
@override
void initState() {
Logger.log('设置分享页面不弹');

/// 设置分享页面不弹
IntellectCreate.setCheck(false);
NetUtil.request('/api/v1/mod/${widget.skipIdentifier}', method: NetMethod.GET, onCache: (data) {
@@ -57,6 +59,7 @@ class _ShareAlertState extends State<ShareAlert> {
@override
void dispose() {
Logger.log('设置智能弹窗可以弹');

/// 之后可以弹
IntellectCreate.setCheck(true);
super.dispose();
@@ -120,12 +123,6 @@ class _ShareAlertContent extends StatefulWidget {
class _ShareAlertContentState extends State<_ShareAlertContent> {
@override
void initState() {
Future.delayed(Duration(milliseconds: 100), () async {
var status = await Permission.storage.status;
if (status != PermissionStatus.granted) {
status = await Permission.storage.request();
}
});
super.initState();
}

@@ -188,8 +185,8 @@ class _ShareAlertContentState extends State<_ShareAlertContent> {
spacing: 10,
runSpacing: 10,
children: widget.iconModel?.icons?.map((item) {
return _createIcon(item);
})?.toList() ??
return _createIcon(item);
})?.toList() ??
[],
);
}
@@ -222,9 +219,16 @@ class _ShareAlertContentState extends State<_ShareAlertContent> {
//检查是否有存储权限
var status = await Permission.storage.status;
if (!status.isGranted) {
status = await Permission.storage.request();
print(status);
return;
var result = await showDialog(context: context, child: NotificationSettingDialogNew([NotificationSettingDialogNew.storagePermissModel]));
if (result != null && result) {
await Permission.storage.request();
if (await Permission.storage.isPermanentlyDenied) {
openAppSettings();
return;
}
} else {
return;
}
}
int count = 0;
if (widget.model.poster != null) {
@@ -299,8 +303,8 @@ class _ShareAlertContentState extends State<_ShareAlertContent> {
}
if (plateform == ShareSDKPlatforms.qZone && widget?.model?.content != null) {
widget?.model?.title = null;
widget?.model?.image=[];
widget?.model?.url=null;
widget?.model?.image = [];
widget?.model?.url = null;
type = SSDKContentTypes.message;
}

@@ -392,10 +396,13 @@ class _ShareAlertContentState extends State<_ShareAlertContent> {
// 检查并请求权限
var status = await Permission.storage.status;
if (status != PermissionStatus.granted) {
status = await Permission.storage.request();
var result = await showDialog(context: context, child: NotificationSettingDialogNew([NotificationSettingDialogNew.storagePermissModel]));
if (result != null && result) {
status = await Permission.storage.request();
}
}
if (status != PermissionStatus.granted) {
Fluttertoast.showToast(msg: '暂无权限,分享失败');
Fluttertoast.showToast(msg: '暂无存储权限,分享失败');
return null;
}



+ 8
- 1
lib/widgets/share/share_alert_select.dart Vedi File

@@ -18,6 +18,7 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:share_extend/share_extend.dart';
import 'package:sharesdk_plugin/sharesdk_plugin.dart';
import 'package:zhiying_base_widget/dialog/global_dialog/intellect_search_goods_dialog/intellect_create.dart';
import 'package:zhiying_base_widget/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart';
import 'package:zhiying_base_widget/dialog/loading/loading.dart';
import 'package:zhiying_base_widget/utils/image_download_util/image_download_util.dart';
import 'package:zhiying_base_widget/widgets/share/models/share_alert_model.dart';
@@ -378,7 +379,13 @@ class _ShareAlertContentState extends State<_ShareAlertContent> {
//检查是否有存储权限
var status = await Permission.storage.status;
if (!status.isGranted) {
status = await Permission.storage.request();
var result = await showDialog(context: context, child: NotificationSettingDialogNew([NotificationSettingDialogNew.storagePermissModel]));
if(result!=null&&result){
status = await Permission.storage.request();
}
if(!status.isGranted){
Fluttertoast.showToast(msg: '暂无存储权限,分享失败');
}
print(status);
return;
}


+ 3
- 2
lib/zhiying_base_widget.dart Vedi File

@@ -4,9 +4,10 @@ export 'dialog/loading/loading.dart';
export 'package:flutter_swiper/flutter_swiper.dart';
export 'package:zhiying_base_widget/pages/main_page/model/background_model.dart';
export 'package:zhiying_base_widget/pages/custom_page/bloc/background_bloc.dart';
export 'package:pull_to_refresh/pull_to_refresh.dart';
export 'package:pull_to_refresh/pull_to_refresh.dart';
export 'package:flutter_user_agent/flutter_user_agent.dart';
export 'package:zhiying_base_widget/widgets/restart_widget/restart_widget.dart';
export 'package:amap_flutter_location/amap_flutter_location.dart';
export 'package:amap_flutter_location/amap_location_option.dart';
export 'package:tab_indicator_styler/tab_indicator_styler.dart';
export 'package:tab_indicator_styler/tab_indicator_styler.dart';
export 'package:zhiying_base_widget/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart';

Caricamento…
Annulla
Salva