|
|
@@ -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'), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|