import 'dart:ui';
|
|
import 'package:flutter/material.dart';
|
import 'package:flutter_html/flutter_html.dart';
|
import 'package:html/dom.dart' as dom;
|
|
class NotifyDialog extends Dialog {
|
BuildContext? context;
|
final String title;
|
final String content;
|
final GestureTapCallback onCancel;
|
final GestureTapCallback onSure;
|
final bool richText;
|
final double fontSize;
|
final double height;
|
final Color contentColor;
|
bool touchOutCancel = false;
|
|
NotifyDialog(this.title, this.content, this.onCancel, this.onSure,
|
{this.fontSize = 16.0,
|
this.richText = false,
|
this.height = 240,
|
this.contentColor = const Color(0xFF7E7E7E)});
|
|
Widget getContent() {
|
if (richText) {
|
return SingleChildScrollView(
|
child: Html(
|
data: content,
|
style: {
|
"a": Style(
|
textDecoration: TextDecoration.none,
|
)
|
},
|
onLinkTap: (String? url, RenderContext context,
|
Map<String, String> attributes, dom.Element? element) {}));
|
} else {
|
return Text(
|
content,
|
style: TextStyle(color: contentColor, fontSize: fontSize),
|
);
|
}
|
}
|
|
Offset? offset;
|
|
|
@override
|
Widget build(BuildContext context) {
|
this.context = context;
|
double width = MediaQuery.of(context).size.width;
|
double dialogWidth = width * 4 / 5;
|
print("屏幕宽:$width");
|
|
//关闭弹框
|
// Navigator.pop(context);
|
return Listener(
|
onPointerDown: touchOutCancel == true
|
? (event) {
|
Offset pos = event.position;
|
if (offset == null ||
|
pos.dy != offset!.dy ||
|
pos.dx != offset!.dx) {
|
print("点击外区域");
|
Navigator.pop(context);
|
}
|
}
|
: null,
|
child: Material(
|
type: MaterialType.transparency,
|
child: Align(
|
alignment: Alignment.center,
|
child: GestureDetector(
|
onPanDown: (event) {
|
offset = event.globalPosition;
|
},
|
child: Container(
|
decoration: BoxDecoration(
|
borderRadius: BorderRadius.all(Radius.circular(15)),
|
color: Colors.white),
|
alignment: Alignment.topCenter,
|
height: height,
|
width: dialogWidth,
|
child: Flex(
|
mainAxisAlignment: MainAxisAlignment.start,
|
direction: Axis.vertical,
|
children: [
|
//-------标题区域--------
|
Container(
|
alignment: Alignment.center,
|
height: 60,
|
child: Text(
|
title,
|
style: TextStyle(
|
fontSize: 18, color: Colors.white),
|
),
|
decoration: BoxDecoration(
|
color: Color(0xFF1CC7FF),
|
borderRadius: BorderRadius.only(
|
topLeft: Radius.circular(15),
|
topRight: Radius.circular(15)),
|
)),
|
//-------内容区域--------
|
Expanded(
|
child: Container(
|
alignment: Alignment.center,
|
padding: EdgeInsets.fromLTRB(15, 5, 15, 5),
|
child: getContent(),
|
)),
|
|
//------按钮区域--------
|
Flex(
|
direction: Axis.horizontal,
|
children: [
|
Expanded(
|
child: InkWell(
|
onTap: () {
|
Navigator.pop(context);
|
onCancel();
|
},
|
child: Container(
|
margin: EdgeInsets.fromLTRB(15, 0, 6, 15),
|
alignment: Alignment.center,
|
height: 44,
|
decoration: BoxDecoration(
|
border:
|
Border.all(color: Color(0xFF0E96FF)),
|
borderRadius: BorderRadius.circular(10)),
|
child: Text(
|
"取消",
|
style: TextStyle(
|
color: Color(0xFF0E96FF), fontSize: 18),
|
),
|
),
|
)),
|
Expanded(
|
child: InkWell(
|
onTap: () {
|
Navigator.pop(context);
|
onSure();
|
},
|
child: Container(
|
margin: EdgeInsets.fromLTRB(6, 0, 15, 15),
|
alignment: Alignment.center,
|
height: 44,
|
decoration: BoxDecoration(
|
color: Color(0xFF0E96FF),
|
borderRadius: BorderRadius.circular(10)),
|
child: Text(
|
"同意",
|
style: TextStyle(
|
color: Colors.white, fontSize: 18),
|
),
|
),
|
))
|
],
|
)
|
],
|
),
|
)))));
|
}
|
}
|
|
class PermissionNotifyDialog extends Dialog {
|
final GestureTapCallback onOpen;
|
|
PermissionNotifyDialog(this.onOpen);
|
|
@override
|
Widget build(BuildContext context) {
|
double width = MediaQuery.of(context).size.width;
|
double dialogWidth = width * 4 / 5;
|
print("屏幕宽:$width");
|
//关闭弹框
|
// Navigator.pop(context);
|
return Material(
|
type: MaterialType.transparency,
|
child: Align(
|
alignment: Alignment.center,
|
child: Container(
|
width: dialogWidth,
|
child: Flex(
|
mainAxisAlignment: MainAxisAlignment.center,
|
direction: Axis.vertical,
|
children: [
|
Image.asset(
|
"assets/images/common/ic_permission_notify_top.png"),
|
Container(
|
padding: EdgeInsets.all(16),
|
decoration: BoxDecoration(
|
borderRadius: BorderRadius.only(
|
bottomLeft: Radius.circular(15),
|
bottomRight: Radius.circular(15)),
|
color: Colors.white),
|
child: Flex(
|
direction: Axis.vertical,
|
children: [
|
getPermissionItem(
|
title: "手机",
|
content: "校验手机识别码,防止账号被盗",
|
icon: Image.asset(
|
"assets/images/common/icon_permission_notify_phone.png",
|
width: 21,
|
)),
|
Container(
|
height: 30,
|
),
|
getPermissionItem(
|
title: "定位",
|
content: "缓存图片和视频,降低流量消耗",
|
icon: Image.asset(
|
"assets/images/common/icon_permission_notify_location.png",
|
width: 26,
|
)),
|
Container(
|
height: 36,
|
),
|
InkWell(
|
onTap: () {
|
onOpen();
|
},
|
child: Container(
|
height: 44,
|
alignment: Alignment.center,
|
decoration: BoxDecoration(
|
borderRadius: BorderRadius.circular(10),
|
color: const Color(0xFF0E96FF)),
|
child: const Text(
|
"立即开启",
|
style: TextStyle(
|
fontSize: 18, color: Colors.white),
|
),
|
),
|
)
|
],
|
),
|
),
|
],
|
))));
|
}
|
|
//权限项
|
Widget getPermissionItem(
|
{required Image icon, required String title, required String content}) {
|
return Flex(
|
direction: Axis.horizontal,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
children: [
|
Container(
|
width: 34,
|
),
|
icon,
|
Container(
|
width: 4,
|
),
|
Expanded(
|
child: Flex(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
direction: Axis.vertical,
|
children: [
|
Text(title,
|
style: TextStyle(fontSize: 17, color: Color(0xFF6B6B6B))),
|
Text(content,
|
style: TextStyle(fontSize: 12, color: Color(0xFFA0A0A0)),
|
softWrap: false,
|
overflow: TextOverflow.ellipsis)
|
],
|
))
|
],
|
);
|
}
|
}
|