video_detail.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/res/gaps.dart';
  3. import 'package:liftmanager/net/api_service.dart';
  4. import 'package:liftmanager/utils/toast.dart';
  5. import 'package:liftmanager/widgets/app_bar.dart';
  6. import 'package:liftmanager/internal/search/search_router.dart';
  7. import 'package:liftmanager/widgets/app_search_bar.dart';
  8. import 'package:liftmanager/res/resources.dart';
  9. import 'package:liftmanager/routers/fluro_navigator.dart';
  10. import 'package:liftmanager/widgets/load_image.dart';
  11. import 'package:liftmanager/widgets/selected_image.dart';
  12. import 'package:image_picker/image_picker.dart';
  13. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  14. import 'dart:io';
  15. import 'package:flutter_screenutil/flutter_screenutil.dart';
  16. import 'package:video_player/video_player.dart';
  17. import 'package:chewie/chewie.dart';
  18. import 'package:liftmanager/internal/bbs/model/video_detail.dart';
  19. import 'package:liftmanager/utils/url.dart';
  20. import 'package:liftmanager/utils/time_format.dart';
  21. import 'dart:convert';
  22. import 'package:shared_preferences/shared_preferences.dart';
  23. import 'package:liftmanager/internal/wode/wode_router.dart';
  24. import 'package:liftmanager/utils/utils.dart';
  25. import 'package:flutter/services.dart';
  26. import 'package:orientation/orientation.dart';
  27. import 'package:image/image.dart' as I;
  28. import 'dart:math';
  29. import 'dart:typed_data';
  30. class VideoDetail extends StatefulWidget {
  31. VideoDetail(this.id);
  32. final String id;
  33. @override
  34. State<StatefulWidget> createState() {
  35. return VideoDetailState();
  36. }
  37. }
  38. class VideoDetailState extends State<VideoDetail> {
  39. @override
  40. void initState() {
  41. super.initState();
  42. getVideoDetail();
  43. }
  44. // final FijkPlayer player = FijkPlayer();
  45. bool _hasData = false;
  46. VideoDetailModel detailObj;
  47. VideoPlayerController _controller;
  48. Future getVideoDetail() async {
  49. await NewApiService().getVideoDetail(int.parse(widget.id), 1,
  50. onSuccess: (res) async {
  51. if (res != null) {
  52. _hasData = true;
  53. detailObj = res;
  54. _controller = VideoPlayerController.network(
  55. Utils.getImagePath(detailObj.url)
  56. // imgFontUrl + detailObj.url
  57. );
  58. // player.setDataSource(detailObj.url, autoPlay: false,showCover: true);
  59. // player.setOption(FijkOption.playerCategory, "cover-after-prepared", 1);
  60. // var imageData = await player.takeSnapShot();
  61. // Image.memory(imageData);
  62. // MemoryImage(imageData);
  63. // I.Image _img = I.decodeImage(imageData);
  64. // _img = I.encodeJpg(_img) as I.Image;
  65. // String s = new String.fromCharCodes(imageData);
  66. // var outputAsUint8List = new Uint8List.fromList(s.codeUnits);
  67. // print(123456);
  68. // print(outputAsUint8List);
  69. // print(1234561);
  70. setState(() {});
  71. }
  72. }, onError: (code, msg) {
  73. toasts(msg);
  74. });
  75. }
  76. @override
  77. void dispose() {
  78. _controller.pause();
  79. _controller.dispose();
  80. // SystemChrome.setPreferredOrientations([
  81. // DeviceOrientation.portraitUp,
  82. // ]);
  83. // player.release();
  84. // OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  85. super.dispose();
  86. }
  87. @override
  88. Widget build(BuildContext context) {
  89. double width = MediaQuery.of(context).size.width;
  90. double height = MediaQuery.of(context).size.height;
  91. if(width > height){
  92. // SystemChrome.setPreferredOrientations([
  93. // DeviceOrientation.portraitUp,
  94. // ]);
  95. OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  96. }
  97. return Scaffold(
  98. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  99. appBar: MyAppBar(
  100. centerTitle: "视频详情",
  101. actions: <Widget>[
  102. _hasData && detailObj.checkFlag==0?FlatButton(
  103. child: Text(
  104. "编辑",
  105. style: TextStyle(
  106. color: Colors.white, fontSize: ScreenUtil().setSp(15)),
  107. ),
  108. textColor: Colours.dark_text,
  109. highlightColor: Colors.transparent,
  110. onPressed: () {
  111. // NavigatorUtils.push(context, WodeRouter.videoUpload);
  112. NavigatorUtils.push(context, "${WodeRouter.videoUpload}?id=${widget.id}");
  113. },
  114. ):Container(child: null,)
  115. ],
  116. ),
  117. body: _hasData
  118. ? Stack(
  119. children: <Widget>[
  120. Container(
  121. child: ListView(children: <Widget>[
  122. Column(
  123. mainAxisAlignment: MainAxisAlignment.start,
  124. crossAxisAlignment: CrossAxisAlignment.start,
  125. children: <Widget>[
  126. Container(
  127. padding: EdgeInsets.only(
  128. left: ScreenUtil().setWidth(15),
  129. right: ScreenUtil().setWidth(15),
  130. top: ScreenUtil().setWidth(15)),
  131. child: ClipRRect(
  132. borderRadius: BorderRadius.circular(5),
  133. child: new Chewie(
  134. controller: ChewieController(
  135. videoPlayerController:
  136. _controller,
  137. aspectRatio: 3 / 2,
  138. autoPlay: false,
  139. looping: true,
  140. showControls: true,
  141. deviceOrientationsAfterFullScreen:[DeviceOrientation.portraitUp],
  142. // 占位图
  143. // placeholder: Image.network(
  144. // imgFontUrl+detailObj.cover,
  145. // fit: BoxFit.contain,
  146. // ),
  147. // 是否在 UI 构建的时候就加载视频
  148. autoInitialize: true,
  149. // 拖动条样式颜色
  150. materialProgressColors:
  151. new ChewieProgressColors(
  152. playedColor: Colors.red,
  153. handleColor: Colors.blue,
  154. backgroundColor: Colors.grey,
  155. bufferedColor: Colors.lightGreen,
  156. ),
  157. ),
  158. ),
  159. )),
  160. Container(
  161. width: width,
  162. padding: EdgeInsets.only(
  163. left: ScreenUtil().setWidth(15),
  164. right: ScreenUtil().setWidth(15),
  165. top: ScreenUtil().setWidth(10),
  166. bottom: ScreenUtil().setWidth(10)),
  167. decoration: BoxDecoration(
  168. border: Border(
  169. bottom: BorderSide(width: 0.5, color: Colours.line),
  170. ),
  171. ),
  172. child: Column(
  173. mainAxisAlignment: MainAxisAlignment.start,
  174. crossAxisAlignment: CrossAxisAlignment.start,
  175. children: <Widget>[
  176. Text(
  177. detailObj.title,
  178. style: TextStyle(
  179. color: Color(0xff000000),
  180. fontSize: ScreenUtil().setSp(16)),
  181. textAlign: TextAlign.start,
  182. ),
  183. Text(
  184. detailObj.brandName,
  185. style: TextStyle(
  186. color: Color(0xff666666),
  187. fontSize: ScreenUtil().setSp(14)),
  188. textAlign: TextAlign.start,
  189. ),
  190. ]),
  191. ),
  192. Container(
  193. padding: EdgeInsets.only(
  194. left: ScreenUtil().setWidth(15),
  195. top: ScreenUtil().setWidth(30),
  196. bottom: ScreenUtil().setWidth(30)),
  197. decoration: BoxDecoration(
  198. border: Border(
  199. bottom: BorderSide(width: 0.5, color: Colours.line),
  200. ),
  201. ),
  202. child: Row(
  203. children: <Widget>[
  204. Container(
  205. child: ClipRRect(
  206. borderRadius: BorderRadius.circular(
  207. ScreenUtil().setWidth(18)),
  208. child: LoadNetworkImage(
  209. detailObj.avatarUrl,
  210. // fit: BoxFit.cover,
  211. width: ScreenUtil().setWidth(36),
  212. height: ScreenUtil().setWidth(36),
  213. ),
  214. )),
  215. Container(
  216. padding: EdgeInsets.only(left: 5),
  217. child: Column(
  218. crossAxisAlignment: CrossAxisAlignment.start,
  219. children: <Widget>[
  220. Text(
  221. detailObj.nickname,
  222. style: TextStyle(
  223. fontSize: ScreenUtil().setSp(14),
  224. color: Color(0xff333333)),
  225. ),
  226. Text(
  227. DateUtils.instance.getFormartData(
  228. timeSamp: detailObj.createTime,
  229. format: "yyyy-MM-dd"),
  230. style: TextStyle(
  231. fontSize: ScreenUtil().setSp(12),
  232. color: Color(0xffaaaaaa)),
  233. ),
  234. ],
  235. ),
  236. )
  237. ],
  238. ),
  239. ),
  240. Column(
  241. crossAxisAlignment: CrossAxisAlignment.start,
  242. mainAxisAlignment: MainAxisAlignment.start,
  243. children: <Widget>[
  244. Container(
  245. padding: EdgeInsets.only(
  246. left: ScreenUtil().setWidth(15),
  247. top: ScreenUtil().setWidth(10),
  248. bottom: ScreenUtil().setWidth(5)),
  249. child: Text(
  250. "视频简介",
  251. style: TextStyle(
  252. color: Color(0xff222222),
  253. fontSize: ScreenUtil().setSp(16),
  254. ),
  255. textAlign: TextAlign.left,
  256. ),
  257. ),
  258. Container(
  259. padding: EdgeInsets.only(
  260. left: ScreenUtil().setWidth(15),
  261. right: ScreenUtil().setWidth(15),
  262. top: ScreenUtil().setWidth(10),
  263. bottom: ScreenUtil().setWidth(90)),
  264. child: Text(
  265. detailObj.descr,
  266. style: TextStyle(
  267. color: Color(0xff222222),
  268. fontSize: ScreenUtil().setSp(14),
  269. ),
  270. textAlign: TextAlign.left,
  271. ),
  272. ),
  273. ],
  274. ),
  275. detailObj.checkFlag==0? Column(
  276. crossAxisAlignment: CrossAxisAlignment.start,
  277. mainAxisAlignment: MainAxisAlignment.start,
  278. children: <Widget>[
  279. Container(
  280. padding: EdgeInsets.only(
  281. left: ScreenUtil().setWidth(15),
  282. top: ScreenUtil().setWidth(10),
  283. bottom: ScreenUtil().setWidth(5)),
  284. child: Text(
  285. "驳回原因",
  286. style: TextStyle(
  287. color: Color(0xff222222),
  288. fontSize: ScreenUtil().setSp(16),
  289. ),
  290. textAlign: TextAlign.left,
  291. ),
  292. ),
  293. Container(
  294. padding: EdgeInsets.only(
  295. left: ScreenUtil().setWidth(15),
  296. right: ScreenUtil().setWidth(15),
  297. top: ScreenUtil().setWidth(10),
  298. bottom: ScreenUtil().setWidth(90)),
  299. child: Text(
  300. detailObj.checkComment,
  301. style: TextStyle(
  302. color: Color(0xff222222),
  303. fontSize: ScreenUtil().setSp(14),
  304. ),
  305. textAlign: TextAlign.left,
  306. ),
  307. ),
  308. ],
  309. ):Container(child: null,),
  310. ],
  311. ),
  312. ])),
  313. ],
  314. )
  315. : Center(
  316. child: Text("正在加载..."),
  317. ),
  318. );
  319. }
  320. }