From 7d25fda292d2ed121f20a1f695b2500dcd0ff1ef Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Wed, 18 Nov 2020 14:53:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8D=8F=E8=AE=AE=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dart_tool/package_config.json | 2 +- .../policy_dialog/policy_confirm_dialog.dart | 70 +++++++----- .../policy_dialog/policy_dialog.dart | 100 ++++++++++-------- lib/pages/home_page/home_page.dart | 13 +-- 4 files changed, 111 insertions(+), 74 deletions(-) diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 3c59bf5..cd5ba64 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -650,7 +650,7 @@ "languageVersion": "2.8" } ], - "generated": "2020-11-17T09:51:34.034604Z", + "generated": "2020-11-18T05:43:02.817433Z", "generator": "pub", "generatorVersion": "2.8.2" } diff --git a/lib/dialog/global_dialog/policy_dialog/policy_confirm_dialog.dart b/lib/dialog/global_dialog/policy_dialog/policy_confirm_dialog.dart index 1ddd707..c1f4ce7 100644 --- a/lib/dialog/global_dialog/policy_dialog/policy_confirm_dialog.dart +++ b/lib/dialog/global_dialog/policy_dialog/policy_confirm_dialog.dart @@ -1,25 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/dialog/global_dialog/policy_dialog/policy_dialog_model.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; -class PolicyConfirmDialog extends StatefulWidget { - @override - _PolicyConfirmDialogState createState() => _PolicyConfirmDialogState(); -} +class PolicyConfirmDialog extends StatelessWidget { + final PolicyDialogModel model; -class _PolicyConfirmDialogState extends State { - @override - Widget build(BuildContext context) { - return _PolicyConfirmDialogContainer(); - } -} + const PolicyConfirmDialog(this.model, {Key key}) : super(key: key); -class _PolicyConfirmDialogContainer extends StatefulWidget { - @override - _PolicyConfirmDialogContainerState createState() => - _PolicyConfirmDialogContainerState(); -} - -class _PolicyConfirmDialogContainerState - extends State<_PolicyConfirmDialogContainer> { @override Widget build(BuildContext context) { return Scaffold( @@ -34,12 +21,21 @@ class _PolicyConfirmDialogContainerState child: Column( children: [ Text( - '温馨提示', - style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + model?.title ?? '', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: HexColor.fromHex(model?.titleColor ?? '#333333')), ), Padding( padding: const EdgeInsets.only(top: 8.0, bottom: 8.0), - child: Text('若得不到您的同意,我们将无法继续为您服务哦,您要不要在想想?'), + child: Text( + model?.content ?? '', + style: TextStyle( + fontSize: 12, + color: HexColor.fromHex(model?.contentColor ?? '#555555'), + ), + ), ), Row( children: [ @@ -50,8 +46,20 @@ class _PolicyConfirmDialogContainerState }, child: Container( height: 36, - color: Colors.redAccent, - child: Text('仍不同意'), + child: Center( + child: Text( + model?.leftBfnText ?? '', + style: TextStyle( + color: HexColor.fromHex( + model?.leftBfnTextColor ?? '')), + ), + ), + decoration: BoxDecoration( + color: HexColor.fromHex( + model?.leftBfnBgColor ?? '#ffffff'), + borderRadius: BorderRadius.circular(18), + border: Border.all( + color: Color(0xffd8d8d8), width: 1)), ), ), ), @@ -65,10 +73,22 @@ class _PolicyConfirmDialogContainerState }, child: Container( height: 36, - color: Colors.redAccent, + child: Center( + child: Text( + model?.rightBfnText ?? '', + style: TextStyle( + color: HexColor.fromHex( + model?.rightBfnTextColor ?? '')), + ), + ), + decoration: BoxDecoration( + color: + HexColor.fromHex(model?.rightBfnBgColor ?? ''), + borderRadius: BorderRadius.circular(18), + ), ), ), - ) + ), ], ) ], diff --git a/lib/dialog/global_dialog/policy_dialog/policy_dialog.dart b/lib/dialog/global_dialog/policy_dialog/policy_dialog.dart index 93d7c29..618532c 100644 --- a/lib/dialog/global_dialog/policy_dialog/policy_dialog.dart +++ b/lib/dialog/global_dialog/policy_dialog/policy_dialog.dart @@ -12,9 +12,9 @@ class PolicyDialog extends StatefulWidget { static Future show(BuildContext context) async { Map json = - await NetUtil.post('/api/v1/app/permissions', method: NetMethod.GET); + await NetUtil.post('/api/v1/app/permissions', method: NetMethod.GET); PolicyDialogModel model = - PolicyDialogModel.fromJson(Map.from(json['data'])); + PolicyDialogModel.fromJson(Map.from(json['data'])); bool agree = null; while (agree == null) { agree = await showCupertinoDialog( @@ -26,7 +26,8 @@ class PolicyDialog extends StatefulWidget { bool accept = null; while (accept == null) { accept = await showCupertinoDialog( - context: context, builder: (_) => PolicyConfirmDialog()); + context: context, + builder: (_) => PolicyConfirmDialog(model.subDialog)); } return accept; } @@ -83,7 +84,7 @@ class _PolicyDialogState extends State { widget.model?.leftBfnBgColor ?? '#ffffff'), borderRadius: BorderRadius.circular(18), border: - Border.all(color: Color(0xffd8d8d8), width: 1)), + Border.all(color: Color(0xffd8d8d8), width: 1)), ), ), ), @@ -123,47 +124,62 @@ class _PolicyDialogState extends State { } Widget _createText() { + String content = widget.model?.content ?? ''; + Map replaces = Map(); + List indexs = List(); + widget.model?.selectedText?.forEach((replace) { + int index = content.indexOf(replace.key); + indexs.add(index); + replaces[index] = replace; + // Logger.debug(replace.key); + }); + // 倒序,从后面开始替换 + indexs.sort((a, b) { + return b.compareTo(a); + }); + List texts = List(); + int end = content.length - 1; + for (int index in indexs) { + // Logger.debug(index); + PolicyItemModel replace = replaces[index]; + texts.insert(0, + TextSpan( + text: content.substring(index + replace.key.length, end), + ), + ); + texts.insert(0, + TextSpan( + text: replace?.text ?? '', + recognizer: TapGestureRecognizer() + ..onTap = () { + NativeUtil.openUrl(context, replace?.url ?? ''); + }, + style: TextStyle( + color: HexColor.fromHex(widget.model?.selectedColor ?? '#FF4242'), + ), + ), + ); + end = index; + } + if (end != 0) { + texts.insert(0, + TextSpan( + text: content.substring(0, end), + ), + ); + } + return RichText( textAlign: TextAlign.left, text: TextSpan( - text: '', - style: TextStyle( - height: 1.2, - fontSize: 12, - color: HexColor.fromHex('#555555'), - ), - children: [ - TextSpan( - text: '亲爱的用户,感谢您对智莺生活的信任!\n\n我们根据最新的监管政策要求,我们更新了', - ), - TextSpan( - text: '《用户协议》', - recognizer: TapGestureRecognizer() - ..onTap = () { - NativeUtil.openUrl(context, 'http://www.baidu.com'); - }, - style: TextStyle( - color: HexColor.fromHex('#FF4242'), - ), - ), - TextSpan( - text: '和', - ), - TextSpan( - text: '《隐私权政策》', - style: TextStyle( - color: HexColor.fromHex('#FF4242'), - ), - recognizer: TapGestureRecognizer() - ..onTap = () { - NativeUtil.openUrl(context, 'http://www.baidu.com'); - }, - ), - TextSpan( - text: - ',请您在点击「同意」之前仔细阅读并充分理解。\n\n为了提供更好的服务,我们在特此说明:\n\n1.在您授权通过的情况下,我们将获取您的设备、位置等信息。您有权拒绝或取消授权;\n\n2.系统的安全保障措施,会严密的保护您的个人信息;\n\n3.未经您本人授权同意,我们不会从任何第三方处获取您的信息,也不会预期分享您的信息。', - ), - ]), + text: '', + style: TextStyle( + height: 1.2, + fontSize: 12, + color: HexColor.fromHex('#555555'), + ), + children: texts, + ), ); } } diff --git a/lib/pages/home_page/home_page.dart b/lib/pages/home_page/home_page.dart index a1e7d18..226794a 100644 --- a/lib/pages/home_page/home_page.dart +++ b/lib/pages/home_page/home_page.dart @@ -11,6 +11,7 @@ import 'package:zhiying_base_widget/dialog/global_dialog/policy_dialog/policy_di import 'package:zhiying_base_widget/utils/contants.dart'; import 'package:zhiying_comm/models/base/base_tab_model.dart'; import 'package:zhiying_comm/util/image_util.dart'; +import 'package:zhiying_comm/util/shared_prefe_util.dart'; import 'package:zhiying_comm/util/update/app_update_util.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; @@ -41,12 +42,12 @@ class _HomePageState extends State { AppUpdateUtil.updateApp(context); TaobaoAuth.initAuth(context); - // SharedPreferencesUtil.getStringValue(Constants.isShowPolicy).then((value) { - // Logger.debug(value); - // if (value == null || value == '') { - // _showPolicy(); - // } - // }); + SharedPreferencesUtil.getStringValue(Constants.isShowPolicy).then((value) { + Logger.debug(value); + if (value == null || value == '') { + _showPolicy(); + } + }); super.initState(); }