|
@@ -1,43 +1,58 @@ |
|
|
|
|
|
import 'dart:io'; |
|
|
|
|
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart'; |
|
|
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/dialog/global_dialog/notification_setting_dialog/notification_setting_model.dart'; |
|
|
|
|
|
import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart'; |
|
|
import 'package:zhiying_base_widget/widgets/home/home_quick_entry/cached_network_image_util.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; |
|
|
import 'dart:convert' as convert; |
|
|
|
|
|
|
|
|
|
|
|
import 'package:package_info/package_info.dart'; |
|
|
|
|
|
|
|
|
class NotificationSettingDialog extends StatelessWidget { |
|
|
class NotificationSettingDialog extends StatelessWidget { |
|
|
|
|
|
|
|
|
final NotificationSettingModel model; |
|
|
final NotificationSettingModel model; |
|
|
|
|
|
|
|
|
const NotificationSettingDialog(this.model, {Key key}) : super(key: key); |
|
|
const NotificationSettingDialog(this.model, {Key key}) : super(key: key); |
|
|
|
|
|
|
|
|
static Future show(BuildContext context) async { |
|
|
static Future show(BuildContext context) async { |
|
|
|
|
|
|
|
|
Map result = |
|
|
|
|
|
await NetUtil.post('/api/v1/mod/pub.flutter.push_dialog', method: NetMethod.GET); |
|
|
|
|
|
|
|
|
Map result = await NetUtil.post('/api/v1/mod/pub.flutter.push_dialog', method: NetMethod.GET); |
|
|
if (!EmptyUtil.isEmpty(result)) { |
|
|
if (!EmptyUtil.isEmpty(result)) { |
|
|
var modListData = result['data']['mod_list'][0]['data']; |
|
|
var modListData = result['data']['mod_list'][0]['data']; |
|
|
if (!EmptyUtil.isEmpty(modListData)) { |
|
|
if (!EmptyUtil.isEmpty(modListData)) { |
|
|
// return EmptyPageModel.fromJson(jsonDecode(modListData)); |
|
|
// return EmptyPageModel.fromJson(jsonDecode(modListData)); |
|
|
// |
|
|
// |
|
|
// String d = json['data']['data']; |
|
|
// String d = json['data']['data']; |
|
|
Map<String, dynamic> da = |
|
|
|
|
|
Map<String, dynamic>.from(convert.jsonDecode(modListData)); |
|
|
|
|
|
|
|
|
Map<String, dynamic> da = Map<String, dynamic>.from(convert.jsonDecode(modListData)); |
|
|
NotificationSettingModel model = NotificationSettingModel.fromJson(Map<String, dynamic>.from(da)); |
|
|
NotificationSettingModel model = NotificationSettingModel.fromJson(Map<String, dynamic>.from(da)); |
|
|
|
|
|
|
|
|
await showCupertinoDialog( |
|
|
|
|
|
context: context, builder: (_) => NotificationSettingDialog(model)); |
|
|
|
|
|
|
|
|
await showCupertinoDialog(context: context, builder: (_) => NotificationSettingDialog(model)); |
|
|
|
|
|
|
|
|
PermissionStatus status = await Permission.notification.status; |
|
|
|
|
|
if (status != PermissionStatus.granted) { |
|
|
|
|
|
|
|
|
if (!await Permission.notification.isGranted) { |
|
|
await Permission.notification.request(); |
|
|
await Permission.notification.request(); |
|
|
|
|
|
if (await Permission.notification.isDenied) { |
|
|
|
|
|
var packageInfo = await PackageInfo.fromPlatform(); |
|
|
|
|
|
await showDialog( |
|
|
|
|
|
context: context, |
|
|
|
|
|
child: TipDialog( |
|
|
|
|
|
btnText: "去打开", |
|
|
|
|
|
content: "系统检查到您还未开启通知权限,可通过以下指引打开通知权限\n 设置 -> 应用管理 -> " + (packageInfo?.appName ?? "") + " -> 通知管理", |
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
if (Platform.isAndroid) { |
|
|
|
|
|
NativeUtil.openAppSettings(); |
|
|
|
|
|
} else { |
|
|
|
|
|
openAppSettings(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!await Permission.storage.isGranted) { |
|
|
|
|
|
await Permission.storage.request(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
@@ -62,20 +77,16 @@ class NotificationSettingDialog extends StatelessWidget { |
|
|
Stack( |
|
|
Stack( |
|
|
children: <Widget>[ |
|
|
children: <Widget>[ |
|
|
ClipRRect( |
|
|
ClipRRect( |
|
|
borderRadius: BorderRadius.only( |
|
|
|
|
|
topLeft: Radius.circular(10), |
|
|
|
|
|
topRight: Radius.circular(10)), |
|
|
|
|
|
|
|
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)), |
|
|
child: CachedNetworkImage( |
|
|
child: CachedNetworkImage( |
|
|
fit: BoxFit.fitWidth, |
|
|
fit: BoxFit.fitWidth, |
|
|
imageUrl: |
|
|
|
|
|
model?.bgStackImg ?? '', |
|
|
|
|
|
|
|
|
imageUrl: model?.bgStackImg ?? '', |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
Transform.translate( |
|
|
Transform.translate( |
|
|
offset: Offset(0, -15), |
|
|
offset: Offset(0, -15), |
|
|
child: CachedNetworkImage( |
|
|
child: CachedNetworkImage( |
|
|
imageUrl: |
|
|
|
|
|
model?.bgOnStackImg ?? '', |
|
|
|
|
|
|
|
|
imageUrl: model?.bgOnStackImg ?? '', |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
], |
|
|
], |
|
@@ -92,8 +103,7 @@ class NotificationSettingDialog extends StatelessWidget { |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
Padding( |
|
|
Padding( |
|
|
padding: |
|
|
|
|
|
const EdgeInsets.only(left: 8.0, right: 8.0, bottom: 4), |
|
|
|
|
|
|
|
|
padding: const EdgeInsets.only(left: 8.0, right: 8.0, bottom: 4), |
|
|
child: Text( |
|
|
child: Text( |
|
|
model?.subtitle ?? '', |
|
|
model?.subtitle ?? '', |
|
|
style: TextStyle( |
|
|
style: TextStyle( |
|
@@ -103,12 +113,13 @@ class NotificationSettingDialog extends StatelessWidget { |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
Column(children: model?.list.map((e) => _createItem(e)).toList() ?? [],), |
|
|
|
|
|
|
|
|
Column( |
|
|
|
|
|
children: model?.list.map((e) => _createItem(e)).toList() ?? [], |
|
|
|
|
|
), |
|
|
GestureDetector( |
|
|
GestureDetector( |
|
|
onTap: () async { |
|
|
onTap: () async { |
|
|
// 检查并请求权限 |
|
|
// 检查并请求权限 |
|
|
PermissionStatus status = |
|
|
|
|
|
await Permission.notification.request(); |
|
|
|
|
|
|
|
|
PermissionStatus status = await Permission.notification.request(); |
|
|
if (status == PermissionStatus.denied) { |
|
|
if (status == PermissionStatus.denied) { |
|
|
await openAppSettings(); |
|
|
await openAppSettings(); |
|
|
} else if (status != PermissionStatus.granted) { |
|
|
} else if (status != PermissionStatus.granted) { |
|
@@ -121,7 +132,9 @@ class NotificationSettingDialog extends StatelessWidget { |
|
|
margin: EdgeInsets.only(top: 10, bottom: 10), |
|
|
margin: EdgeInsets.only(top: 10, bottom: 10), |
|
|
width: 120, |
|
|
width: 120, |
|
|
height: 60, |
|
|
height: 60, |
|
|
child: CachedNetworkImage(imageUrl: model?.btnImg ?? '',), |
|
|
|
|
|
|
|
|
child: CachedNetworkImage( |
|
|
|
|
|
imageUrl: model?.btnImg ?? '', |
|
|
|
|
|
), |
|
|
), |
|
|
), |
|
|
) |
|
|
) |
|
|
], |
|
|
], |
|
@@ -132,7 +145,9 @@ class NotificationSettingDialog extends StatelessWidget { |
|
|
width: 30, |
|
|
width: 30, |
|
|
height: 30, |
|
|
height: 30, |
|
|
margin: EdgeInsets.only(top: 10), |
|
|
margin: EdgeInsets.only(top: 10), |
|
|
child: CachedNetworkImage(imageUrl: model?.deleteImg ?? '',), |
|
|
|
|
|
|
|
|
child: CachedNetworkImage( |
|
|
|
|
|
imageUrl: model?.deleteImg ?? '', |
|
|
|
|
|
), |
|
|
), |
|
|
), |
|
|
onTap: () { |
|
|
onTap: () { |
|
|
Navigator.pop(context); |
|
|
Navigator.pop(context); |
|
@@ -152,11 +167,12 @@ class NotificationSettingDialog extends StatelessWidget { |
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
children: <Widget>[ |
|
|
children: <Widget>[ |
|
|
Container( |
|
|
Container( |
|
|
margin: EdgeInsets.only(right: 6, top: 2), |
|
|
|
|
|
width: 20, |
|
|
|
|
|
height: 20, |
|
|
|
|
|
child: CachedNetworkImage(imageUrl: itemModel?.icon ?? '',) |
|
|
|
|
|
), |
|
|
|
|
|
|
|
|
margin: EdgeInsets.only(right: 6, top: 2), |
|
|
|
|
|
width: 20, |
|
|
|
|
|
height: 20, |
|
|
|
|
|
child: CachedNetworkImage( |
|
|
|
|
|
imageUrl: itemModel?.icon ?? '', |
|
|
|
|
|
)), |
|
|
Expanded( |
|
|
Expanded( |
|
|
child: Column( |
|
|
child: Column( |
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|