|
|
|
|
|
|
|
|
|
|
|
import 'package:chewie/chewie.dart';
|
|
|
|
import 'package:flutter_html/flutter_html.dart';
|
|
|
|
import 'package:flutter_html/image_render.dart';
|
|
|
|
import 'package:chewie/src/chewie_progress_colors.dart' as chewie;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_html/src/replaced_element.dart';
|
|
|
|
import 'package:flutter_html/style.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/activity.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/article.dart';
|
|
|
|
import 'package:video_player/video_player.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.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: Colors.white
|
|
|
|
)
|
|
|
|
},
|
|
|
|
onLinkTap: (url, ct, attributes, element) {
|
|
|
|
if(attributes.containsKey("storeid")){
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
'/router/store_order',
|
|
|
|
arguments: {
|
|
|
|
"id": attributes["storeid"],
|
|
|
|
"tenant": attributes["tenantcode"],
|
|
|
|
"storeName": attributes["storename"]
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onImageTap: (url,ct,attributes, element) {
|
|
|
|
if(attributes.containsKey("storeid")){
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
'/router/store_order',
|
|
|
|
arguments: {
|
|
|
|
"id": attributes["storeid"],
|
|
|
|
"tenant": attributes["tenantcode"],
|
|
|
|
"storeName": attributes["storename"]
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
customImageRenders: {
|
|
|
|
assetUriMatcher(): assetImageRender(),
|
|
|
|
networkSourceMatcher(extension: "svg"):
|
|
|
|
svgNetworkImageRender(),
|
|
|
|
networkSourceMatcher(): networkImageRender(
|
|
|
|
loadingWidget: () {
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
customRender: {
|
|
|
|
"video":
|
|
|
|
(context, parsedChild) {
|
|
|
|
var src = context.tree.element.attributes["src"];
|
|
|
|
return videoWidget(
|
|
|
|
double.tryParse(context.tree.element.attributes["width"] ?? ""),
|
|
|
|
double.tryParse(
|
|
|
|
context.tree.element.attributes["height"] ?? ""),
|
|
|
|
(src != null &&
|
|
|
|
src != "" &&
|
|
|
|
src.endsWith(".mp4"))
|
|
|
|
? src
|
|
|
|
: context.tree.children.first.attributes["src"],
|
|
|
|
context.tree.attributes["sandbox"]);
|
|
|
|
},
|
|
|
|
"iframe":
|
|
|
|
(context, parsedChild) {
|
|
|
|
var src = context.tree.element.children.firstWhere((element) => element.localName == "source").attributes["src"];
|
|
|
|
return videoWidget(
|
|
|
|
double.tryParse(context.style.width ?? ""),
|
|
|
|
double.tryParse(context.style.height ?? ""),
|
|
|
|
(src != null &&
|
|
|
|
src != "" &&
|
|
|
|
src.endsWith(".mp4"))
|
|
|
|
? src
|
|
|
|
: context.tree.children.first.attributes["src"],
|
|
|
|
context.tree.attributes["sandbox"]);
|
|
|
|
},
|
|
|
|
"audio":
|
|
|
|
(context, parsedChild) {
|
|
|
|
final sources = <String>[
|
|
|
|
if (context.tree.attributes['src'] != null)
|
|
|
|
context.tree.attributes['src'],
|
|
|
|
];
|
|
|
|
if (sources == null ||
|
|
|
|
sources.isEmpty ||
|
|
|
|
sources.first == null) {
|
|
|
|
return EmptyContentElement();
|
|
|
|
}
|
|
|
|
return audioWidget(
|
|
|
|
context.tree.attributes['controls'] != null,
|
|
|
|
context.tree.attributes['loop'] != null,
|
|
|
|
context.tree.attributes['autoplay'] != null,
|
|
|
|
sources,
|
|
|
|
context.style.width ?? 300.w,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoPlayerController videoPlayerController;
|
|
|
|
ChewieController chewieAudioController;
|
|
|
|
Chewie chewies;
|
|
|
|
|
|
|
|
Widget videoWidget(double width, double height, src, sandboxMode) {
|
|
|
|
print("src : $src");
|
|
|
|
chewieAudioController = ChewieController(
|
|
|
|
videoPlayerController: videoPlayerController =
|
|
|
|
VideoPlayerController.network(
|
|
|
|
src,
|
|
|
|
),
|
|
|
|
aspectRatio: width / height,
|
|
|
|
//宽高比
|
|
|
|
autoPlay: false,
|
|
|
|
//自动播放
|
|
|
|
looping: false,
|
|
|
|
//循环播放
|
|
|
|
allowFullScreen: true,
|
|
|
|
// systemOverlaysAfterFullScreen: [],
|
|
|
|
// systemOverlaysOnEnterFullScreen: [],
|
|
|
|
// deviceOrientationsAfterFullScreen: [],
|
|
|
|
// deviceOrientationsOnEnterFullScreen: [],
|
|
|
|
// 拖动条样式颜色
|
|
|
|
materialProgressColors: chewie.ChewieProgressColors(
|
|
|
|
playedColor: Colors.white,
|
|
|
|
handleColor: Colors.white,
|
|
|
|
backgroundColor: Colors.grey,
|
|
|
|
bufferedColor: Colors.transparent,
|
|
|
|
),
|
|
|
|
autoInitialize: true,
|
|
|
|
);
|
|
|
|
|
|
|
|
chewieAudioController.addListener(_fullScreenListener);
|
|
|
|
|
|
|
|
return MediaQuery(
|
|
|
|
data: MediaQuery.of(context).copyWith(
|
|
|
|
textScaleFactor: 0.9,
|
|
|
|
),
|
|
|
|
child: Container(
|
|
|
|
width: MediaQuery.of(context).size.width - 17,
|
|
|
|
height: (MediaQuery.of(context).size.width) / (width / height),
|
|
|
|
child: chewies = Chewie(
|
|
|
|
controller: chewieAudioController,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _fullScreenListener() async {
|
|
|
|
print("object: isPlaying: ${videoPlayerController.value.isPlaying}");
|
|
|
|
print("object: isFullScreen: ${chewieAudioController.isFullScreen}");
|
|
|
|
|
|
|
|
if (!chewieAudioController.isFullScreen) {
|
|
|
|
Future.delayed(Duration(seconds: 1), () {
|
|
|
|
widget.exitFull();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget audioWidget(showControls, loop, autoplay, src, width) {
|
|
|
|
return Container(
|
|
|
|
width: width,
|
|
|
|
child: chewies = Chewie(
|
|
|
|
controller: chewieAudioController = ChewieController(
|
|
|
|
videoPlayerController: VideoPlayerController.network(
|
|
|
|
src.first ?? "",
|
|
|
|
),
|
|
|
|
autoPlay: autoplay,
|
|
|
|
looping: loop,
|
|
|
|
showControls: showControls,
|
|
|
|
autoInitialize: true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
|
|
|
|
if (chewieAudioController != null) {
|
|
|
|
chewieAudioController.pause();
|
|
|
|
chewieAudioController.dispose();
|
|
|
|
chewieAudioController = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (videoPlayerController != null) {
|
|
|
|
videoPlayerController.pause();
|
|
|
|
videoPlayerController.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|