|
@@ -119,14 +119,7 @@ class NotificationSettingDialog extends StatelessWidget { |
|
|
), |
|
|
), |
|
|
GestureDetector( |
|
|
GestureDetector( |
|
|
onTap: () async { |
|
|
onTap: () async { |
|
|
// 检查并请求权限 |
|
|
|
|
|
PermissionStatus status = await Permission.notification.request(); |
|
|
|
|
|
if (status == PermissionStatus.denied) { |
|
|
|
|
|
await openAppSettings(); |
|
|
|
|
|
} else if (status != PermissionStatus.granted) { |
|
|
|
|
|
status = await Permission.notification.request(); |
|
|
|
|
|
} |
|
|
|
|
|
Navigator.pop(context); |
|
|
|
|
|
|
|
|
Navigator.pop(context, true); |
|
|
return true; |
|
|
return true; |
|
|
}, |
|
|
}, |
|
|
child: Container( |
|
|
child: Container( |
|
@@ -202,3 +195,191 @@ class NotificationSettingDialog extends StatelessWidget { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class NotificationSettingDialogNew extends StatelessWidget { |
|
|
|
|
|
List<PermissModel> permissModels; |
|
|
|
|
|
|
|
|
|
|
|
NotificationSettingDialogNew(this.permissModels, {Key key}) : super(key: key); |
|
|
|
|
|
|
|
|
|
|
|
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")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!await Permission.notification.isGranted) { |
|
|
|
|
|
newPermissModels.add(PermissModel( |
|
|
|
|
|
permissType: PermissType.notification, |
|
|
|
|
|
title: "通知权限", |
|
|
|
|
|
subTitle: "用于及时告知优惠动态", |
|
|
|
|
|
iconUrl: "https://alipic.lanhuapp.com/SketchPnga11a94a0c38949016e0fced74d683c08eaa1f58366cba616a40e51a9ebbe7146")); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
newPermissModels = permissModels; |
|
|
|
|
|
} |
|
|
|
|
|
if (newPermissModels.length == 0) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
await showCupertinoDialog(context: context, builder: (_) => NotificationSettingDialogNew(newPermissModels)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
|
return Scaffold( |
|
|
|
|
|
backgroundColor: Colors.transparent, |
|
|
|
|
|
body: Container( |
|
|
|
|
|
width: double.infinity, |
|
|
|
|
|
child: Column( |
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
|
|
children: <Widget>[ |
|
|
|
|
|
Container( |
|
|
|
|
|
width: 280, |
|
|
|
|
|
padding: EdgeInsets.all(20), |
|
|
|
|
|
// height: 382, |
|
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
|
color: Colors.white, |
|
|
|
|
|
borderRadius: BorderRadius.circular(10), |
|
|
|
|
|
), |
|
|
|
|
|
child: Column( |
|
|
|
|
|
children: <Widget>[ |
|
|
|
|
|
Text( |
|
|
|
|
|
"申请获取权限", |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
fontSize: 15, |
|
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
|
color: HexColor.fromHex('#FF4242'), |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
SizedBox( |
|
|
|
|
|
height: 10, |
|
|
|
|
|
), |
|
|
|
|
|
Text( |
|
|
|
|
|
" \t\t\t\t\t为了保证您可以正常使用APP, 更好地为您提供服务, 我们需要向您申请获得如下权限", |
|
|
|
|
|
style: TextStyle(fontSize: 13, color: HexColor.fromHex("#FF666666")), |
|
|
|
|
|
), |
|
|
|
|
|
SizedBox( |
|
|
|
|
|
height: 10, |
|
|
|
|
|
), |
|
|
|
|
|
Column( |
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
|
children: permissModels.map((e) => _createItem(e)).toList() ?? [], |
|
|
|
|
|
), |
|
|
|
|
|
SizedBox( |
|
|
|
|
|
height: 20, |
|
|
|
|
|
), |
|
|
|
|
|
GestureDetector( |
|
|
|
|
|
onTap: () async { |
|
|
|
|
|
for (var item in permissModels) { |
|
|
|
|
|
if (item.permissType == PermissType.notification) { |
|
|
|
|
|
if (!await Permission.notification.isGranted) { |
|
|
|
|
|
await Permission.notification.request(); |
|
|
|
|
|
if (await Permission.notification.isDenied) { |
|
|
|
|
|
if (Platform.isAndroid) { |
|
|
|
|
|
await NativeUtil.openAppSettings(); |
|
|
|
|
|
} else { |
|
|
|
|
|
openAppSettings(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else if (item.permissType == PermissType.storage) { |
|
|
|
|
|
if (!await Permission.storage.isGranted) { |
|
|
|
|
|
await Permission.storage.request(); |
|
|
|
|
|
} |
|
|
|
|
|
if (await Permission.storage.isPermanentlyDenied) { |
|
|
|
|
|
openAppSettings(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
Navigator.pop(context, true); |
|
|
|
|
|
}, |
|
|
|
|
|
child: Container( |
|
|
|
|
|
margin: EdgeInsets.only(top: 10, bottom: 10), |
|
|
|
|
|
height: 38, |
|
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
|
borderRadius: BorderRadius.circular(8), |
|
|
|
|
|
gradient: |
|
|
|
|
|
LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [HexColor.fromHex("#FFFF5632"), HexColor.fromHex("#FFFF4242")])), |
|
|
|
|
|
child: Center( |
|
|
|
|
|
child: Text( |
|
|
|
|
|
"确认授权", |
|
|
|
|
|
style: TextStyle(color: Colors.white, fontSize: 13), |
|
|
|
|
|
))), |
|
|
|
|
|
) |
|
|
|
|
|
], |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
GestureDetector( |
|
|
|
|
|
onTap: () { |
|
|
|
|
|
Navigator.pop(context, false); |
|
|
|
|
|
}, |
|
|
|
|
|
child: Container(width: 30, height: 30, margin: EdgeInsets.only(top: 10), child: CloseButton(color: HexColor.fromHex("#FFFFFF")))) |
|
|
|
|
|
], |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Widget _createItem(PermissModel itemModel) { |
|
|
|
|
|
return Container( |
|
|
|
|
|
decoration: BoxDecoration(color: HexColor.fromHex("#FFFAFAFA"), borderRadius: BorderRadius.circular(8)), |
|
|
|
|
|
margin: EdgeInsets.only(top: 8), |
|
|
|
|
|
child: Padding( |
|
|
|
|
|
padding: EdgeInsets.only(left: 8, right: 8, top: 4, bottom: 4), |
|
|
|
|
|
child: Row( |
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
|
|
|
|
children: <Widget>[ |
|
|
|
|
|
Container( |
|
|
|
|
|
margin: EdgeInsets.only(right: 6, top: 2), |
|
|
|
|
|
width: 27, |
|
|
|
|
|
height: 27, |
|
|
|
|
|
child: CachedNetworkImage( |
|
|
|
|
|
imageUrl: itemModel?.iconUrl ?? '', |
|
|
|
|
|
)), |
|
|
|
|
|
Expanded( |
|
|
|
|
|
child: Column( |
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
|
children: <Widget>[ |
|
|
|
|
|
Text( |
|
|
|
|
|
itemModel?.title ?? '', |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
fontSize: 14, |
|
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
|
color: HexColor.fromHex('#333333'), |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
Text( |
|
|
|
|
|
itemModel?.subTitle ?? '', |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
fontSize: 11, |
|
|
|
|
|
fontWeight: FontWeight.normal, |
|
|
|
|
|
color: HexColor.fromHex('#999999'), |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
], |
|
|
|
|
|
), |
|
|
|
|
|
) |
|
|
|
|
|
], |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class PermissModel { |
|
|
|
|
|
String iconUrl; |
|
|
|
|
|
String title; |
|
|
|
|
|
String subTitle; |
|
|
|
|
|
PermissType permissType; |
|
|
|
|
|
|
|
|
|
|
|
PermissModel({this.iconUrl, this.title, this.subTitle, this.permissType}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enum PermissType { notification, storage } |