video_detail.dart 14 KB

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