From 0daa197dbaf611eacdf9eeb3763ddcb10038585b Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 03 十一月 2021 19:20:07 +0800 Subject: [PATCH] 功能完善 --- lib/ui/widget/dialog.dart | 323 ++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 245 insertions(+), 78 deletions(-) diff --git a/lib/ui/widget/dialog.dart b/lib/ui/widget/dialog.dart index c219a97..d0fd9f6 100644 --- a/lib/ui/widget/dialog.dart +++ b/lib/ui/widget/dialog.dart @@ -1,14 +1,170 @@ 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); + 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) { @@ -22,84 +178,95 @@ child: Align( alignment: Alignment.center, child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(15)), - color: Colors.white), - alignment: Alignment.topCenter, - height: 240, - 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), - ), + 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( - 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: Text( - content, - style: TextStyle(color: Color(0xFF7E7E7E), fontSize: 16), + 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), + ), + ), + ) + ], + ), ), - )), - 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), - ), - ), - )) - ], - ) - ], - ), - ))); + ], + )))); + } + + //鏉冮檺椤� + 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) + ], + )) + ], + ); } } -- Gitblit v1.8.0