import 'dart:ui';
|
|
import 'package:flutter/material.dart';
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
import '../../ui/search/search.dart';
|
import 'package:html/dom.dart' as dom;
|
import '../../ui/common/browser.dart';
|
import '../../utils/pageutils.dart';
|
import '../../utils/ui_constant.dart';
|
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
|
import '../widget/nav.dart';
|
|
//通用弹框
|
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;
|
final String cancelName;
|
final String sureName;
|
|
NotifyDialog(this.title, this.content, this.onCancel, this.onSure,
|
{this.fontSize = 16.0,
|
this.richText = false,
|
this.height = 240,
|
this.contentColor = const Color(0xFF333333),
|
this.cancelName = "取消",
|
this.sureName = "确定"});
|
|
Widget getContent(BuildContext context) {
|
if (richText) {
|
return SingleChildScrollView(
|
child: HtmlWidget(content, onTapUrl: (String url) {
|
NavigatorUtil.navigateToNextPage(
|
context,
|
BrowserPage(
|
title: "",
|
url: url,
|
),
|
(data) {});
|
|
return true;
|
}));
|
} 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 WillPopScope(
|
onWillPop: () async {
|
return false;
|
},
|
child: Material(
|
type: MaterialType.transparency,
|
child: Align(
|
alignment: Alignment.center,
|
child: Container(
|
decoration: const 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: const BoxDecoration(
|
color: ColorConstant.theme,
|
borderRadius: BorderRadius.only(
|
topLeft: Radius.circular(15),
|
topRight: Radius.circular(15)),
|
)),
|
//-------内容区域--------
|
Expanded(
|
child: Container(
|
alignment: Alignment.center,
|
padding: const EdgeInsets.fromLTRB(15, 5, 15, 5),
|
child: getContent(context),
|
)),
|
|
//------按钮区域--------
|
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: ColorConstant.theme),
|
borderRadius: BorderRadius.circular(10)),
|
child: Text(
|
cancelName,
|
style: const TextStyle(
|
color: ColorConstant.theme, fontSize: 18),
|
),
|
),
|
)),
|
Expanded(
|
child: InkWell(
|
onTap: () {
|
Navigator.pop(context);
|
onSure();
|
},
|
child: Container(
|
margin: const EdgeInsets.fromLTRB(6, 0, 15, 15),
|
alignment: Alignment.center,
|
height: 44,
|
decoration: BoxDecoration(
|
color: ColorConstant.theme,
|
borderRadius: BorderRadius.circular(10)),
|
child: Text(
|
sureName,
|
style: const 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 WillPopScope(
|
onWillPop: () async {
|
return false;
|
},
|
child: 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/imgs/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/imgs/common/icon_permission_notify_phone.png",
|
width: 21,
|
)),
|
Container(
|
height: 30,
|
),
|
getPermissionItem(
|
title: "存储",
|
content: "缓存图片和视频,降低流量消耗",
|
icon: Image.asset(
|
"assets/imgs/common/icon_permission_notify_save.png",
|
width: 26,
|
)),
|
Container(
|
height: 30,
|
),
|
getPermissionItem(
|
title: "位置",
|
content: "定位用户",
|
icon: Image.asset(
|
"assets/imgs/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)
|
],
|
))
|
],
|
);
|
}
|
}
|
|
///ListView弹框
|
class ListViewDialog extends Dialog {
|
BuildContext? context;
|
final ListView listView;
|
final GestureTapCallback onClose;
|
final double maxHeight;
|
final double? dwidth;
|
|
ListViewDialog(this.listView, this.onClose,
|
{this.maxHeight = 420, this.dwidth});
|
|
@override
|
Widget build(BuildContext context) {
|
this.context = context;
|
double swidth = MediaQuery.of(context).size.width;
|
|
double dialogWidth = swidth - 20;
|
print("屏幕宽:$swidth");
|
if (dwidth != null) {
|
dialogWidth = dwidth!;
|
}
|
//关闭弹框
|
// Navigator.pop(context);
|
return WillPopScope(
|
onWillPop: () async {
|
return false;
|
},
|
child: Material(
|
type: MaterialType.transparency,
|
child: Align(
|
alignment: Alignment.center,
|
child: Column(
|
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisSize: MainAxisSize.min,
|
children: [
|
ClipRRect(
|
borderRadius: BorderRadius.circular(10),
|
child: Container(
|
constraints: BoxConstraints(maxHeight: maxHeight),
|
color: Colors.white,
|
alignment: Alignment.topCenter,
|
width: dialogWidth,
|
child: listView,
|
)),
|
Container(
|
height: 20,
|
),
|
InkWell(
|
child: Image.asset(
|
"assets/imgs/common/icon_dialog_close.png",
|
height: 32,
|
width: 32,
|
),
|
onTap: () {
|
onClose();
|
},
|
),
|
]))));
|
}
|
}
|
|
///ListView弹框
|
class LoadingDialog extends Dialog {
|
BuildContext? context;
|
final String? text;
|
|
LoadingDialog(this.text);
|
|
@override
|
Widget build(BuildContext context) {
|
this.context = context;
|
|
//关闭弹框
|
// Navigator.pop(context);
|
return WillPopScope(
|
onWillPop: () async {
|
return false;
|
},
|
child: const Material(
|
type: MaterialType.transparency,
|
child: Align(
|
alignment: Alignment.center,
|
child: SpinKitCircle(
|
color: ColorConstant.theme,
|
size: 80.0,
|
))));
|
}
|
}
|
|
class CustomDialog extends Dialog {
|
BuildContext? context;
|
final Widget contentWidget;
|
|
CustomDialog(this.contentWidget);
|
|
@override
|
Widget build(BuildContext context) {
|
this.context = context;
|
//关闭弹框
|
// Navigator.pop(context);
|
return WillPopScope(
|
onWillPop: () async {
|
return false;
|
},
|
child: Material(
|
type: MaterialType.transparency,
|
child: Align(
|
alignment: Alignment.center,
|
child: Column(
|
mainAxisSize: MainAxisSize.min,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
children: [
|
contentWidget,
|
Container(
|
height: 20,
|
),
|
InkWell(
|
onTap: () {
|
popPage(context);
|
},
|
child: Image.asset(
|
"assets/imgs/common/icon_dialog_close.png",
|
height: 32,
|
width: 32,
|
))
|
],
|
))));
|
}
|
}
|