Browse Source

更新推送权限弹窗

tags/0.0.2+8
杨华轩 4 years ago
parent
commit
8ce3ac6f3c
4 changed files with 171 additions and 67 deletions
  1. +70
    -59
      lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart
  2. +92
    -0
      lib/dialog/global_dialog/notification_setting_dialog/notification_setting_model.dart
  3. +5
    -6
      lib/pages/home_page/home_page.dart
  4. +4
    -2
      lib/utils/contants.dart

+ 70
- 59
lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart View File

@@ -2,29 +2,46 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:zhiying_base_widget/dialog/global_dialog/notification_setting_dialog/notification_setting_model.dart';
import 'package:zhiying_base_widget/widgets/home/home_quick_entry/cached_network_image_util.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'dart:convert' as convert;

class NotificationSettingDialog extends StatefulWidget {
@override
_NotificationSettingDialogState createState() =>
_NotificationSettingDialogState();
}

class _NotificationSettingDialogState extends State<NotificationSettingDialog> {
@override
Widget build(BuildContext context) {
return _NotificationSettingDialogContainer();
}
}
class NotificationSettingDialog extends StatelessWidget {

class _NotificationSettingDialogContainer extends StatefulWidget {
@override
_NotificationSettingDialogContainerState createState() =>
_NotificationSettingDialogContainerState();
}
final NotificationSettingModel model;

const NotificationSettingDialog(this.model, {Key key}) : super(key: key);

static Future show(BuildContext context) async {

Map result =
await NetUtil.post('/api/v1/mod/pub.flutter.push_dialog', method: NetMethod.GET);
if (!EmptyUtil.isEmpty(result)) {
var modListData = result['data']['mod_list'][0]['data'];
if (!EmptyUtil.isEmpty(modListData)) {
// return EmptyPageModel.fromJson(jsonDecode(modListData));
//
// String d = json['data']['data'];
Map<String, dynamic> da =
Map<String, dynamic>.from(convert.jsonDecode(modListData));
NotificationSettingModel model = NotificationSettingModel.fromJson(Map<String, dynamic>.from(da));

return await showCupertinoDialog(
context: context, builder: (_) => NotificationSettingDialog(model));

PermissionStatus status = await Permission.notification.status;
if (status != PermissionStatus.granted) {
return await showCupertinoDialog(
context: context, builder: (_) => NotificationSettingDialog(model));

}
}
}

}

class _NotificationSettingDialogContainerState
extends State<_NotificationSettingDialogContainer> {
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -44,23 +61,35 @@ class _NotificationSettingDialogContainerState
),
child: Column(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10)),
child: CachedNetworkImage(
imageUrl:
'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1456601714,1347673110&fm=26&gp=0.jpg',
),
Stack(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10)),
child: CachedNetworkImage(
fit: BoxFit.fitWidth,
imageUrl:
model?.bgStackImg ?? '',
),
),
Transform.translate(
offset: Offset(0, -15),
child: CachedNetworkImage(
imageUrl:
model?.bgOnStackImg ?? '',
),
),
],
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'开启推送通知',
model?.title ?? '',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: HexColor.fromHex('#F94400'),
color: HexColor.fromHex(model?.titleColor ?? '#FF4242'),
),
),
),
@@ -68,17 +97,15 @@ class _NotificationSettingDialogContainerState
padding:
const EdgeInsets.only(left: 8.0, right: 8.0, bottom: 4),
child: Text(
'接收服务提醒',
model?.subtitle ?? '',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.normal,
color: HexColor.fromHex('#F94400'),
color: HexColor.fromHex(model?.subtitleColor ?? '#FF4242'),
),
),
),
_createItem(),
_createItem(),
_createItem(),
Column(children: model?.list.map((e) => _createItem(e)).toList() ?? [],),
GestureDetector(
onTap: () async {
// 检查并请求权限
@@ -89,21 +116,14 @@ class _NotificationSettingDialogContainerState
} else if (status != PermissionStatus.granted) {
status = await Permission.notification.request();
}
// if (status == PermissionStatus.denied) {
// Fluttertoast.showToast(msg: '暂无权限');
// return null;
// }
Navigator.pop(context);
return true;
},
child: Container(
margin: EdgeInsets.only(top: 10, bottom: 20),
margin: EdgeInsets.only(top: 10, bottom: 10),
width: 120,
height: 30,
decoration: BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.circular(15),
),
height: 60,
child: CachedNetworkImage(imageUrl: model?.btnImg ?? '',),
),
)
],
@@ -114,16 +134,7 @@ class _NotificationSettingDialogContainerState
width: 30,
height: 30,
margin: EdgeInsets.only(top: 10),
decoration: BoxDecoration(
color: Color(0x70606060),
borderRadius: BorderRadius.circular(15),
),
child: Center(
child: Icon(
Icons.close,
color: Colors.white,
),
),
child: CachedNetworkImage(imageUrl: model?.deleteImg ?? '',),
),
onTap: () {
Navigator.pop(context);
@@ -135,7 +146,7 @@ class _NotificationSettingDialogContainerState
);
}

Widget _createItem() {
Widget _createItem(NotificationSettingItemModel itemModel) {
return Padding(
padding: EdgeInsets.only(left: 30, right: 30, top: 4, bottom: 4),
child: Row(
@@ -146,26 +157,26 @@ class _NotificationSettingDialogContainerState
margin: EdgeInsets.only(right: 6, top: 2),
width: 20,
height: 20,
color: Colors.redAccent,
child: CachedNetworkImage(imageUrl: itemModel?.icon ?? '',)
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'补贴到账通知',
itemModel?.title ?? '',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: HexColor.fromHex('#333333'),
color: HexColor.fromHex(model?.listItemTitleColor ?? '#333333'),
),
),
Text(
'定时为您推荐热门内容, 不再错过好货',
model?.subtitle ?? '',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.normal,
color: HexColor.fromHex('#999999'),
color: HexColor.fromHex(model?.listItemSubtitleColor ?? '#999999'),
),
),
],


+ 92
- 0
lib/dialog/global_dialog/notification_setting_dialog/notification_setting_model.dart View File

@@ -0,0 +1,92 @@
class NotificationSettingModel {
String bgColor;
String bgStackImg;
String bgOnStackImg;
String title;
String titleColor;
String subtitle;
String subtitleColor;
String listItemTitleColor;
String listItemSubtitleColor;
List<NotificationSettingItemModel> list;
String btnImg;
String deleteImg;

NotificationSettingModel(
{this.bgColor,
this.bgStackImg,
this.bgOnStackImg,
this.title,
this.titleColor,
this.subtitle,
this.subtitleColor,
this.listItemTitleColor,
this.listItemSubtitleColor,
this.list,
this.btnImg,
this.deleteImg});

NotificationSettingModel.fromJson(Map<String, dynamic> json) {
bgColor = json['bg_color'];
bgStackImg = json['bg_stack_img'];
bgOnStackImg = json['bg_on_stack_img'];
title = json['title'];
titleColor = json['title_color'];
subtitle = json['subtitle'];
subtitleColor = json['subtitle_color'];
listItemTitleColor = json['list_item_title_color'];
listItemSubtitleColor = json['list_item_subtitle_color'];
if (json['list'] != null) {
list = new List<NotificationSettingItemModel>();
json['list'].forEach((v) {
list.add(new NotificationSettingItemModel.fromJson(v));
});
}
btnImg = json['btn_img'];
deleteImg = json['delete_img'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['bg_color'] = this.bgColor;
data['bg_stack_img'] = this.bgStackImg;
data['bg_on_stack_img'] = this.bgOnStackImg;
data['title'] = this.title;
data['title_color'] = this.titleColor;
data['subtitle'] = this.subtitle;
data['subtitle_color'] = this.subtitleColor;
data['list_item_title_color'] = this.listItemTitleColor;
data['list_item_subtitle_color'] = this.listItemSubtitleColor;
if (this.list != null) {
data['list'] = this.list.map((v) => v.toJson()).toList();
}
data['btn_img'] = this.btnImg;
data['delete_img'] = this.deleteImg;
return data;
}
}

class NotificationSettingItemModel {
String type;
String icon;
String title;
String subtitle;

NotificationSettingItemModel({this.type, this.icon, this.title, this.subtitle});

NotificationSettingItemModel.fromJson(Map<String, dynamic> json) {
type = json['type'];
icon = json['icon'];
title = json['title'];
subtitle = json['subtitle'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['type'] = this.type;
data['icon'] = this.icon;
data['title'] = this.title;
data['subtitle'] = this.subtitle;
return data;
}
}

+ 5
- 6
lib/pages/home_page/home_page.dart View File

@@ -164,8 +164,6 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
Future _showPolicy() async {
String isShowPolicy =
await SharedPreferencesUtil.getStringValue(Constants.isShowPolicy);
isShowPolicy = '';
Logger.debug(isShowPolicy);
if (isShowPolicy == null || isShowPolicy != '1') {
bool isAccept = await PolicyDialog.show(context);
if (!isAccept) {
@@ -175,10 +173,11 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
}
}

PermissionStatus status = await Permission.notification.status;
if (status != PermissionStatus.granted) {
await showCupertinoDialog(
context: context, builder: (_) => NotificationSettingDialog());
String isShowNotiPermission =
await SharedPreferencesUtil.getStringValue(Constants.isShowNotiPermission);
if (isShowNotiPermission == null || isShowNotiPermission != '1') {
await NotificationSettingDialog.show(context);
await SharedPreferencesUtil.setStringValue(Constants.isShowNotiPermission, "1");
}

IntellectCreate.checkAndCreateFirst(context);


+ 4
- 2
lib/utils/contants.dart View File

@@ -18,9 +18,11 @@ class Constants {

//==============================智能粘贴版===================================end

//==============================用户协议===================================start
//==============================弹窗===================================start
///用户协议显示
static String isShowPolicy = "is_show_policy";
//==============================用户协议===================================end
///推送权限弹窗
static String isShowNotiPermission = "isShowNotiPermission";
//==============================弹窗===================================end

}

Loading…
Cancel
Save