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.

341 lines
12 KiB

4 years ago
import 'dart:io';
4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
4 years ago
import 'package:flutter_html/flutter_html.dart';
4 years ago
import 'package:flutter_html/image_render.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
import 'package:huixiang/retrofit/data/activity.dart';
import 'package:huixiang/retrofit/data/article.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
4 years ago
import 'package:huixiang/view_widget/share_dialog.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sharesdk_plugin/sharesdk_defines.dart';
import 'package:sharesdk_plugin/sharesdk_interface.dart';
import 'package:sharesdk_plugin/sharesdk_map.dart';
4 years ago
import 'package:video_player/video_player.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:flutter_html/src/replaced_element.dart';
import 'package:flutter/cupertino.dart';
import 'package:chewie/src/chewie_progress_colors.dart' as chewie;
import 'package:chewie/chewie.dart';
4 years ago
class StoreDetailsPage extends StatefulWidget {
4 years ago
final Map<String, dynamic> arguments;
4 years ago
///富文本 文章 活动
4 years ago
StoreDetailsPage({this.arguments});
4 years ago
@override
State<StatefulWidget> createState() {
return _StoreDetailsPage();
}
}
class _StoreDetailsPage extends State<StoreDetailsPage> {
4 years ago
ApiService apiService;
4 years ago
@override
void initState() {
super.initState();
4 years ago
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
4 years ago
SharedPreferences.getInstance().then((value) {
apiService =
ApiService(Dio(), context: context, token: value.getString("token"));
4 years ago
queryHtml();
});
}
Activity activity;
Article article;
queryHtml() async {
BaseData baseData = await apiService.informationInfo(
widget.arguments["activityId"] ?? widget.arguments["articleId"]);
4 years ago
if (baseData != null && baseData.isSuccess) {
4 years ago
if (widget.arguments.containsKey("activityId")) {
activity = Activity.fromJson(baseData.data);
} else if (widget.arguments.containsKey("articleId")) {
article = Article.fromJson(baseData.data);
}
setState(() {});
}
}
4 years ago
share() async {
SSDKMap params = SSDKMap()
..setGeneral(
4 years ago
activity != null
? activity.mainTitle
: article != null
? article.mainTitle
: "",
activity != null
? activity.viceTitle
: article != null
? article.viceTitle
: "",
4 years ago
[
activity != null
? activity.coverImg
: article != null
? article.coverImg
: "",
],
4 years ago
activity != null
? activity.coverImg
: article != null
4 years ago
? article.coverImg
: "",
"",
4 years ago
"http://hx.lotus-wallet.com/index.html?id=${widget.arguments["activityId"] ?? widget.arguments["articleId"]}",
"",
"",
"",
"",
SSDKContentTypes.webpage);
4 years ago
4 years ago
debugPrint(activity != null
? activity.coverImg
: article != null
4 years ago
? article.coverImg
: "");
4 years ago
4 years ago
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
4 years ago
return ShareDialog((platform) {
4 years ago
if (platform == ShareSDKPlatforms.line) {
4 years ago
params.map["type"] = SSDKContentTypes.text.value;
4 years ago
params.map["text"] =
"${activity != null ? activity.viceTitle : article != null ? article.viceTitle : ""} http://hx.lotus-wallet.com/index.html?id=${widget.arguments["activityId"] ?? widget.arguments["articleId"]}";
4 years ago
}
4 years ago
SharesdkPlugin.share(platform, params,
(state, userData, contentEntity, error) {
print("share!$state");
4 years ago
});
});
});
}
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
4 years ago
appBar: MyAppBar(
action: Container(
4 years ago
margin: EdgeInsets.only(right: 10),
child: GestureDetector(
onTap: () {
4 years ago
share();
},
child: Icon(
Icons.share,
size: 24,
color: Colors.black,
4 years ago
),
),
),
4 years ago
background: Color(0xFFF7F7F7),
leadingColor: Colors.black,
title: activity != null
? activity.mainTitle
: article != null
4 years ago
? article.mainTitle
: "",
4 years ago
titleSize: 18.sp,
titleColor: Colors.black,
4 years ago
),
body: Container(
4 years ago
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: [
Container(
padding: EdgeInsets.all(12),
alignment: Alignment.centerLeft,
child: Text(
activity != null
? activity.mainTitle
: article != null
4 years ago
? article.mainTitle
: "",
4 years ago
style: TextStyle(
4 years ago
fontSize: 16.sp,
4 years ago
fontWeight: FontWeight.bold,
color: Color(0xFF353535),
),
),
),
Container(
4 years ago
padding: EdgeInsets.symmetric(horizontal: 12.w),
4 years ago
child: Row(
children: [
4 years ago
InkWell(
child: Text(
4 years ago
"${activity != null ? activity.storeName : (article != null && article.author != null) ? article.author.name : ""}",
4 years ago
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 14.sp,
color: Colors.blue,
),
4 years ago
),
4 years ago
onTap: () {
if (activity != null) {
3 years ago
if (widget.arguments["source"] != null
&& widget.arguments["source"] == activity.storeId) {
Navigator.of(context).pop();
} else {
Navigator.of(context).pushNamed(
'/router/union_detail_page',
arguments: {"id": activity.storeId, "source": widget.arguments["activityId"]});
}
4 years ago
}
},
4 years ago
),
SizedBox(
4 years ago
width: 10.w,
4 years ago
),
Text(
activity != null
? activity.createTime
: article != null
4 years ago
? article.createTime
: "",
4 years ago
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 12.sp,
color: Colors.grey,
),
)
],
),
),
4 years ago
Html(
data: activity != null
? activity.content
: article != null
4 years ago
? article.content
: "",
4 years ago
customImageRenders: {
base64DataUriMatcher(): base64ImageRender(),
assetUriMatcher(): assetImageRender(),
networkSourceMatcher(extension: "svg"):
4 years ago
svgNetworkImageRender(),
4 years ago
networkSourceMatcher(): networkImageRender(
4 years ago
loadingWidget: () {
return Container();
},
4 years ago
// mapUrl: (url) {
// print("objectUrl: $url");
// return "$url?imageMogr2/format/webp/blur/1x0/quality/75";
// },
4 years ago
),
4 years ago
},
4 years ago
customRender: {
4 years ago
"video": (context, parsedChild, attributes, element) {
return videoWidget(
double.tryParse(attributes['width'] ?? ""),
double.tryParse(element.attributes['height'] ?? ""),
element.children.first.attributes["src"],
element.attributes["sandbox"]);
4 years ago
},
4 years ago
"iframe": (context, parsedChild, attributes, element) {
return videoWidget(
double.tryParse(attributes['width'] ?? ""),
double.tryParse(element.attributes['height'] ?? ""),
element.children.first.attributes["src"],
element.attributes["sandbox"]);
4 years ago
},
4 years ago
"audio": (context, parsedChild, attributes, element) {
4 years ago
final sources = <String>[
4 years ago
if (element.attributes['src'] != null)
element.attributes['src'],
4 years ago
];
4 years ago
if (sources == null ||
sources.isEmpty ||
sources.first == null) {
4 years ago
return EmptyContentElement();
}
4 years ago
return audioWidget(
attributes['controls'] != null,
attributes['loop'] != null,
attributes['autoplay'] != null,
sources,
context.style.width ?? 300.w);
4 years ago
},
},
4 years ago
),
4 years ago
],
),
4 years ago
),
),
);
}
4 years ago
4 years ago
VideoPlayerController videoPlayerController;
ChewieController chewieAudioController;
Chewie chewies;
Widget videoWidget(double width, double height, src, sandboxMode) {
print("src : $src");
return Container(
width: MediaQuery.of(context).size.width,
height: (MediaQuery.of(context).size.width) / (width / height),
child: chewies = Chewie(
controller: chewieAudioController = ChewieController(
4 years ago
videoPlayerController: videoPlayerController =
VideoPlayerController.network(
4 years ago
src,
),
aspectRatio: width / height,
//宽高比
autoPlay: !true,
//自动播放
looping: false,
//循环播放
// 拖动条样式颜色
materialProgressColors: chewie.ChewieProgressColors(
playedColor: Colors.white,
handleColor: Colors.white,
backgroundColor: Colors.grey,
bufferedColor: Colors.transparent,
),
autoInitialize: true,
),
),
);
}
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,
),
),
);
}
4 years ago
@override
void dispose() {
4 years ago
if (chewieAudioController != null) chewieAudioController.dispose();
4 years ago
4 years ago
if (videoPlayerController != null) videoPlayerController.dispose();
4 years ago
super.dispose();
4 years ago
}
4 years ago
}