|
@@ -2,29 +2,46 @@ import 'package:cached_network_image/cached_network_image.dart'; |
|
|
import 'package:flutter/cupertino.dart'; |
|
|
import 'package:flutter/cupertino.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:permission_handler/permission_handler.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 '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 |
|
|
@override |
|
|
Widget build(BuildContext context) { |
|
|
Widget build(BuildContext context) { |
|
|
return Scaffold( |
|
|
return Scaffold( |
|
@@ -44,23 +61,35 @@ class _NotificationSettingDialogContainerState |
|
|
), |
|
|
), |
|
|
child: Column( |
|
|
child: Column( |
|
|
children: <Widget>[ |
|
|
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( |
|
|
padding: const EdgeInsets.all(8.0), |
|
|
padding: const EdgeInsets.all(8.0), |
|
|
child: Text( |
|
|
child: Text( |
|
|
'开启推送通知', |
|
|
|
|
|
|
|
|
model?.title ?? '', |
|
|
style: TextStyle( |
|
|
style: TextStyle( |
|
|
fontSize: 16, |
|
|
fontSize: 16, |
|
|
fontWeight: FontWeight.bold, |
|
|
fontWeight: FontWeight.bold, |
|
|
color: HexColor.fromHex('#F94400'), |
|
|
|
|
|
|
|
|
color: HexColor.fromHex(model?.titleColor ?? '#FF4242'), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
@@ -68,17 +97,15 @@ class _NotificationSettingDialogContainerState |
|
|
padding: |
|
|
padding: |
|
|
const EdgeInsets.only(left: 8.0, right: 8.0, bottom: 4), |
|
|
const EdgeInsets.only(left: 8.0, right: 8.0, bottom: 4), |
|
|
child: Text( |
|
|
child: Text( |
|
|
'接收服务提醒', |
|
|
|
|
|
|
|
|
model?.subtitle ?? '', |
|
|
style: TextStyle( |
|
|
style: TextStyle( |
|
|
fontSize: 13, |
|
|
fontSize: 13, |
|
|
fontWeight: FontWeight.normal, |
|
|
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( |
|
|
GestureDetector( |
|
|
onTap: () async { |
|
|
onTap: () async { |
|
|
// 检查并请求权限 |
|
|
// 检查并请求权限 |
|
@@ -89,21 +116,14 @@ class _NotificationSettingDialogContainerState |
|
|
} else if (status != PermissionStatus.granted) { |
|
|
} else if (status != PermissionStatus.granted) { |
|
|
status = await Permission.notification.request(); |
|
|
status = await Permission.notification.request(); |
|
|
} |
|
|
} |
|
|
// if (status == PermissionStatus.denied) { |
|
|
|
|
|
// Fluttertoast.showToast(msg: '暂无权限'); |
|
|
|
|
|
// return null; |
|
|
|
|
|
// } |
|
|
|
|
|
Navigator.pop(context); |
|
|
Navigator.pop(context); |
|
|
return true; |
|
|
return true; |
|
|
}, |
|
|
}, |
|
|
child: Container( |
|
|
child: Container( |
|
|
margin: EdgeInsets.only(top: 10, bottom: 20), |
|
|
|
|
|
|
|
|
margin: EdgeInsets.only(top: 10, bottom: 10), |
|
|
width: 120, |
|
|
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, |
|
|
width: 30, |
|
|
height: 30, |
|
|
height: 30, |
|
|
margin: EdgeInsets.only(top: 10), |
|
|
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: () { |
|
|
onTap: () { |
|
|
Navigator.pop(context); |
|
|
Navigator.pop(context); |
|
@@ -135,7 +146,7 @@ class _NotificationSettingDialogContainerState |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Widget _createItem() { |
|
|
|
|
|
|
|
|
Widget _createItem(NotificationSettingItemModel itemModel) { |
|
|
return Padding( |
|
|
return Padding( |
|
|
padding: EdgeInsets.only(left: 30, right: 30, top: 4, bottom: 4), |
|
|
padding: EdgeInsets.only(left: 30, right: 30, top: 4, bottom: 4), |
|
|
child: Row( |
|
|
child: Row( |
|
@@ -146,26 +157,26 @@ class _NotificationSettingDialogContainerState |
|
|
margin: EdgeInsets.only(right: 6, top: 2), |
|
|
margin: EdgeInsets.only(right: 6, top: 2), |
|
|
width: 20, |
|
|
width: 20, |
|
|
height: 20, |
|
|
height: 20, |
|
|
color: Colors.redAccent, |
|
|
|
|
|
|
|
|
child: CachedNetworkImage(imageUrl: itemModel?.icon ?? '',) |
|
|
), |
|
|
), |
|
|
Expanded( |
|
|
Expanded( |
|
|
child: Column( |
|
|
child: Column( |
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
children: <Widget>[ |
|
|
children: <Widget>[ |
|
|
Text( |
|
|
Text( |
|
|
'补贴到账通知', |
|
|
|
|
|
|
|
|
itemModel?.title ?? '', |
|
|
style: TextStyle( |
|
|
style: TextStyle( |
|
|
fontSize: 14, |
|
|
fontSize: 14, |
|
|
fontWeight: FontWeight.bold, |
|
|
fontWeight: FontWeight.bold, |
|
|
color: HexColor.fromHex('#333333'), |
|
|
|
|
|
|
|
|
color: HexColor.fromHex(model?.listItemTitleColor ?? '#333333'), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
Text( |
|
|
Text( |
|
|
'定时为您推荐热门内容, 不再错过好货', |
|
|
|
|
|
|
|
|
model?.subtitle ?? '', |
|
|
style: TextStyle( |
|
|
style: TextStyle( |
|
|
fontSize: 11, |
|
|
fontSize: 11, |
|
|
fontWeight: FontWeight.normal, |
|
|
fontWeight: FontWeight.normal, |
|
|
color: HexColor.fromHex('#999999'), |
|
|
|
|
|
|
|
|
color: HexColor.fromHex(model?.listItemSubtitleColor ?? '#999999'), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
], |
|
|
], |
|
|