video_detail.dart 17 KB

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