You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
5.1 KiB
136 lines
5.1 KiB
|
|
|
|
import 'package:chewie/chewie.dart'; |
|
import 'package:chewie_audio/chewie_audio.dart'; |
|
import 'package:flutter_html/flutter_html.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter_html_audio/flutter_html_audio.dart'; |
|
import 'package:flutter_html_iframe/flutter_html_iframe.dart'; |
|
import 'package:flutter_html_svg/flutter_html_svg.dart'; |
|
import 'package:flutter_html_video/flutter_html_video.dart'; |
|
import 'package:html/dom.dart' as dom; |
|
import 'package:huixiang/data/activity.dart'; |
|
import 'package:huixiang/data/article.dart'; |
|
import 'package:video_player/video_player.dart'; |
|
|
|
class WebContent extends StatefulWidget { |
|
|
|
final Activity? activity; |
|
final Article? article; |
|
final Function exitFull; |
|
|
|
WebContent(this.activity, this.article, this.exitFull); |
|
|
|
@override |
|
State<StatefulWidget> createState() { |
|
return _WebContent(); |
|
} |
|
|
|
} |
|
|
|
class _WebContent extends State<WebContent> { |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
var htmlCnt = widget.activity?.content??widget.article?.content??""; |
|
var regex = RegExp("\\[jump.*?\\].*?\\[/jump\\]"); |
|
var match = regex.allMatches(htmlCnt); |
|
if(match.length > 0){ |
|
match.forEach((element) { |
|
var viewType = RegExp("viewType=\"(.+?)\"").firstMatch(element.group(0) ?? "")?.group(1); |
|
if(viewType == "text"){ |
|
var cnt = RegExp("\\](.*?)\\[").firstMatch(element.group(0) ?? "")?.group(1); |
|
var storeId = RegExp("storeId=\"(.+?)\"").firstMatch(element.group(0) ?? "")?.group(1); |
|
var storeName = RegExp("storeName=\"(.+?)\"").firstMatch(element.group(0) ?? "")?.group(1); |
|
var tenantCode = RegExp("tenantCode=\"(.+?)\"").firstMatch(element.group(0) ?? "")?.group(1); |
|
var textCnt = "<a storeName=\"${storeName}\" storeId=\"${storeId}\" tenantCode=\"${tenantCode}\" href=\"/\">${cnt}</a>"; |
|
htmlCnt = htmlCnt.replaceAll(element.group(0) ?? "", textCnt); |
|
}else if(viewType == "img"){ |
|
var cnt = RegExp("\\](.*?)\\[").firstMatch(element.group(0) ?? "")?.group(1); |
|
var storeId = RegExp("storeId=\"(.+?)\"").firstMatch(element.group(0) ?? "")?.group(1); |
|
var storeName = RegExp("storeName=\"(.+?)\"").firstMatch(element.group(0) ?? "")?.group(1); |
|
var tenantCode = RegExp("tenantCode=\"(.+?)\"").firstMatch(element.group(0) ?? "")?.group(1); |
|
var textCnt = "<img src=\"${cnt}\" storeName=\"${storeName}\" storeId=\"${storeId}\" tenantCode=\"${tenantCode}\" />"; |
|
htmlCnt = htmlCnt.replaceAll(element.group(0) ?? "", textCnt); |
|
} |
|
}); |
|
} |
|
return Html( |
|
data: htmlCnt, |
|
// + "<a storeName=\"前进麦味烘焙*海峡姐妹茶(哈乐城店)\" storeId=\"1432164681279078400\" tenantCode=\"1175\" href=\"/\">立即购买</a><img storeName=\"前进麦味烘焙*海峡姐妹茶(哈乐城店)\" storeId=\"1432164681279078400\" tenantCode=\"1175\" src=\"https://pos.upload.gznl.top/MDAwMA==/2021/12/6edfe416-aaf9-4f0e-b2a4-4dc85db03489.jpg\" />", |
|
style: { |
|
"html": Style( |
|
backgroundColor: Color(0xffffffff) |
|
) |
|
}, |
|
onLinkTap: (url, attributes, element) { |
|
if(attributes.containsKey("storeid")){ |
|
Navigator.of(context).pushNamed( |
|
'/router/store_order', |
|
arguments: { |
|
"id": attributes["storeid"], |
|
"tenant": attributes["tenantcode"], |
|
"storeName": attributes["storename"] |
|
}, |
|
); |
|
} |
|
}, |
|
onAnchorTap: (url, attributes, element) { |
|
if(attributes.containsKey("storeid")){ |
|
Navigator.of(context).pushNamed( |
|
'/router/store_order', |
|
arguments: { |
|
"id": attributes["storeid"], |
|
"tenant": attributes["tenantcode"], |
|
"storeName": attributes["storename"] |
|
}, |
|
); |
|
} |
|
}, |
|
extensions: [ |
|
SvgHtmlExtension(), |
|
VideoHtmlExtension( |
|
videoControllerCallback: (dom.Element? element, ChewieController chewieController, VideoPlayerController videoPlayerController) { |
|
this.videoPlayerController = videoPlayerController; |
|
this.chewieController = chewieController; |
|
} |
|
), |
|
IframeHtmlExtension(), |
|
AudioHtmlExtension( |
|
audioControllerCallback: (dom.Element? element, ChewieAudioController chewieAudioController, VideoPlayerController videoPlayerController) { |
|
this.videoPlayerController = videoPlayerController; |
|
this.chewieAudioController = chewieAudioController; |
|
} |
|
), |
|
], |
|
); |
|
} |
|
|
|
VideoPlayerController? videoPlayerController; |
|
ChewieAudioController? chewieAudioController; |
|
ChewieController? chewieController; |
|
|
|
@override |
|
void dispose() { |
|
|
|
if (chewieController != null) { |
|
chewieController!.pause(); |
|
chewieController!.dispose(); |
|
chewieController = null; |
|
} |
|
|
|
if (chewieAudioController != null) { |
|
chewieAudioController!.pause(); |
|
chewieAudioController!.dispose(); |
|
chewieAudioController = null; |
|
} |
|
|
|
if (videoPlayerController != null) { |
|
videoPlayerController!.pause(); |
|
videoPlayerController!.dispose(); |
|
} |
|
|
|
super.dispose(); |
|
} |
|
|
|
} |