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 createState() { return _WebContent(); } } class _WebContent extends State { @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 = "${cnt}"; 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 = ""; htmlCnt = htmlCnt.replaceAll(element.group(0) ?? "", textCnt); } }); } return Html( data: htmlCnt, // + "立即购买", 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(); } }