From 7bd49900cbc6c1e17f9a8a0f33cc8ce84a709a85 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Thu, 20 May 2021 16:31:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8C=85=E8=A3=B9=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E8=B5=84=E8=AE=AF=E8=AF=A6=E6=83=85=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E5=B5=8C=E5=85=A5=E8=B6=85=E9=93=BE=E6=8E=A5=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=82=B9=E5=87=BB=E8=B7=B3=E8=BD=AC=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../electronic_commerc_card.dart | 3 +- .../electronic_commerc_detail_page.dart | 7 ++++ .../express_package_view.dart | 7 ++-- .../public_information_detail_page.dart | 35 ++++++++++++++++--- lib/utils/link_text_parase.dart | 23 ++++++++++++ 5 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 lib/utils/link_text_parase.dart diff --git a/lib/pages/electronic_commerc/electronic_commerc_card.dart b/lib/pages/electronic_commerc/electronic_commerc_card.dart index 7b9a12ac..318cfa37 100644 --- a/lib/pages/electronic_commerc/electronic_commerc_card.dart +++ b/lib/pages/electronic_commerc/electronic_commerc_card.dart @@ -13,8 +13,7 @@ import 'package:aku_community/const/resource.dart'; class ElectronicCommercCard extends StatefulWidget { final ElectronicCommercListModel model; - ElectronicCommercCard({Key? key, required this.model}) - : super(key: key); + ElectronicCommercCard({Key? key, required this.model}) : super(key: key); @override _ElectronicCommercCardState createState() => _ElectronicCommercCardState(); diff --git a/lib/pages/electronic_commerc/electronic_commerc_detail_page.dart b/lib/pages/electronic_commerc/electronic_commerc_detail_page.dart index 060ab355..8d873d6c 100644 --- a/lib/pages/electronic_commerc/electronic_commerc_detail_page.dart +++ b/lib/pages/electronic_commerc/electronic_commerc_detail_page.dart @@ -61,6 +61,13 @@ class _ElectronicCommercDetailPageState extends State { @override Widget build(BuildContext context) { - // return ListView( - // padding: EdgeInsets.symmetric(vertical: 16.w, horizontal: 32.w), - // children: [ExpressPackageCard(index: widget.index)], - // ); return BeeListView( path: API.manager.expressPackageList, controller: _refreshController, + extraParams: { + "packageCollectionStatus": widget.index + 1, + }, convert: (models) { return models.tableList ?.map((e) => ExpressPackageListModel.fromJson(e)) diff --git a/lib/ui/home/public_infomation/public_information_detail_page.dart b/lib/ui/home/public_infomation/public_information_detail_page.dart index cfc43523..0b927640 100644 --- a/lib/ui/home/public_infomation/public_information_detail_page.dart +++ b/lib/ui/home/public_infomation/public_information_detail_page.dart @@ -1,13 +1,16 @@ import 'package:aku_community/base/base_style.dart'; import 'package:aku_community/constants/api.dart'; import 'package:aku_community/models/news/news_detail_model.dart'; +import 'package:aku_community/utils/link_text_parase.dart'; import 'package:aku_community/utils/network/base_model.dart'; import 'package:aku_community/utils/network/net_util.dart'; import 'package:aku_community/widget/bee_scaffold.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:flustars/flustars.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:url_launcher/url_launcher.dart'; import 'package:velocity_x/velocity_x.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -25,15 +28,19 @@ class _PublicInformationDetailPageState late EasyRefreshController _easyRefreshController; bool _onload = true; late NewsDetailModel _detailModel; + late List _parasedText; + late TapGestureRecognizer _tapLinkUrlLancher; //设置单击手势识别器 @override void initState() { super.initState(); _easyRefreshController = EasyRefreshController(); + _tapLinkUrlLancher = TapGestureRecognizer(); } @override void dispose() { _easyRefreshController.dispose(); + _tapLinkUrlLancher.dispose(); //释放手势识别器资源 super.dispose(); } @@ -52,6 +59,7 @@ class _PublicInformationDetailPageState }); if (baseModel.status! && baseModel.data != null) { _detailModel = NewsDetailModel.fromJson(baseModel.data); + _parasedText = LinkTextParase.stringParase(_detailModel.content); } else { BotToast.showText(text: '无法获取信息'); } @@ -72,10 +80,29 @@ class _PublicInformationDetailPageState 24.w.heightBox, SizedBox( width: double.infinity, - child: _detailModel.content.text - .size(28.sp) - .color(ktextPrimary) - .make(), + child: RichText( + text: TextSpan( + children: List.generate(_parasedText.length, (index) { + if (index.isEven) { + return TextSpan( + text: _parasedText[index], + style: + TextStyle(fontSize: 28.sp, color: ktextPrimary), + ); + } else { + return TextSpan( + text: _parasedText[index], + style: TextStyle( + fontSize: 28.sp, + color: Colors.lightBlue, + ), + recognizer: _tapLinkUrlLancher + ..onTap = () { + launch(_parasedText[index]); + }); + } + })), + ), ), 40.w.heightBox, Row( diff --git a/lib/utils/link_text_parase.dart b/lib/utils/link_text_parase.dart new file mode 100644 index 00000000..f52c0857 --- /dev/null +++ b/lib/utils/link_text_parase.dart @@ -0,0 +1,23 @@ + + +class LinkTextParase { + static List stringParase(String text, {Pattern? pattern}) { + List _listString = []; + List _urls = []; //匹配到的url存入这个数组 + //使用正则表达式匹配url,将字符串中url前后的部分分割存储为字符串列表 + Pattern _pattern = pattern ?? + RegExp( + r"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]"); //url的正则表达式 + _listString = text.split(_pattern); + var _matches = _pattern.allMatches(text); + for (var item in _matches) { + _urls.add(item[0]!); + print(item[0]); + } + //将url插入字符串数组 + for (var i = 0; i < _urls.length; i++) { + _listString.insert(2 * i + 1, _urls[i]); + } + return _listString; + } +}