Browse Source

1、隐私协议的替换方法更新

tags/0.0.17+6^0
PH2 3 years ago
parent
commit
4fc5fb56c3
1 changed files with 52 additions and 3 deletions
  1. +52
    -3
      lib/dialog/global_dialog/policy_dialog/policy_dialog.dart

+ 52
- 3
lib/dialog/global_dialog/policy_dialog/policy_dialog.dart View File

@@ -11,8 +11,8 @@ class PolicyDialog extends StatefulWidget {
const PolicyDialog(this.model, {Key key}) : super(key: key);

static Future<bool> show(BuildContext context) async {
Map json =
await NetUtil.post('/api/v1/app/permissions', method: NetMethod.GET);
// 旧接口:/api/v1/app/permissions
Map json = await NetUtil.post('/api/v1/app/new_permissions', method: NetMethod.GET);
PolicyDialogModel model =
PolicyDialogModel.fromJson(Map<String, dynamic>.from(json['data']));
bool agree = null;
@@ -58,7 +58,7 @@ class _PolicyDialogState extends State<PolicyDialog> {
child: Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: SingleChildScrollView(
child: _createText(),
child: _createNewText(),
),
),
),
@@ -123,6 +123,55 @@ class _PolicyDialogState extends State<PolicyDialog> {
);
}

/// 新的替换方法
Widget _createNewText() {
String content = widget.model?.content ?? '';
List<TextSpan> texts = List();
if (!EmptyUtil.isEmpty(content)) {
// 需要替换
if (!EmptyUtil.isEmpty(widget?.model?.selectedText)) {
widget.model.selectedText.forEach((item) {
// 切割关键字不等于null,并且content内有找到切割关键字才进行操作
if (!EmptyUtil.isEmpty(item?.key) && content.indexOf(item.key) != -1) {
List<String> tempArr = content.split(item.key);
if (!EmptyUtil.isEmpty(tempArr) && tempArr.length == 2) {
// step1、普通文字
texts.add(TextSpan(text: tempArr[0]));
// step2、点击链接
texts.add(TextSpan(
text: item?.text ?? '',
recognizer: TapGestureRecognizer()
..onTap = () {
NativeUtil.openUrl(context, item?.url ?? '');
},
style: TextStyle(color: HexColor.fromHex(widget.model?.selectedColor ?? '#FF4242')),
));
// step3、更新切割后的数据
content = tempArr[1];
}
}
});
} else {
// 无需替换
texts.add(TextSpan(
text: content
));
}
}
return EmptyUtil.isEmpty(texts) ? Container() : RichText(
textAlign: TextAlign.left,
text: TextSpan(
text: '',
style: TextStyle(
height: 1.2,
fontSize: 14,
color: HexColor.fromHex('#555555'),
),
children: texts),
);
}

// 弃用
Widget _createText() {
String content = widget.model?.content ?? '';
Map<int, PolicyItemModel> replaces = Map();


Loading…
Cancel
Save