video_detail.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 'dart:math';
  28. import 'dart:typed_data';
  29. class VideoDetail extends StatefulWidget {
  30. VideoDetail(this.id);
  31. final String id;
  32. @override
  33. State<StatefulWidget> createState() {
  34. return VideoDetailState();
  35. }
  36. }
  37. class VideoDetailState extends State<VideoDetail> {
  38. @override
  39. void initState() {
  40. super.initState();
  41. getVideoDetail();
  42. }
  43. // final FijkPlayer player = FijkPlayer();
  44. bool _hasData = false;
  45. VideoDetailModel detailObj;
  46. VideoPlayerController _controller;
  47. Future getVideoDetail() async {
  48. await NewApiService().getVideoDetail(int.parse(widget.id), 1,
  49. onSuccess: (res) async {
  50. if (res != null) {
  51. _hasData = true;
  52. detailObj = res;
  53. _controller = VideoPlayerController.network(
  54. Utils.getImagePath(detailObj.url)
  55. // imgFontUrl + detailObj.url
  56. );
  57. // player.setDataSource(detailObj.url, autoPlay: false,showCover: true);
  58. // player.setOption(FijkOption.playerCategory, "cover-after-prepared", 1);
  59. // var imageData = await player.takeSnapShot();
  60. // Image.memory(imageData);
  61. // MemoryImage(imageData);
  62. // I.Image _img = I.decodeImage(imageData);
  63. // _img = I.encodeJpg(_img) as I.Image;
  64. // String s = new String.fromCharCodes(imageData);
  65. // var outputAsUint8List = new Uint8List.fromList(s.codeUnits);
  66. // print(123456);
  67. // print(outputAsUint8List);
  68. // print(1234561);
  69. setState(() {});
  70. }
  71. }, onError: (code, msg) {
  72. toasts(msg);
  73. });
  74. }
  75. @override
  76. void dispose() {
  77. if(_controller!=null){
  78. _controller.pause();
  79. _controller.dispose();
  80. }
  81. // SystemChrome.setPreferredOrientations([
  82. // DeviceOrientation.portraitUp,
  83. // ]);
  84. // player.release();
  85. // OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  86. super.dispose();
  87. }
  88. @override
  89. Widget build(BuildContext context) {
  90. double width = MediaQuery.of(context).size.width;
  91. double height = MediaQuery.of(context).size.height;
  92. if(width > height){
  93. // SystemChrome.setPreferredOrientations([
  94. // DeviceOrientation.portraitUp,
  95. // ]);
  96. OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  97. }
  98. return Scaffold(
  99. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  100. appBar: MyAppBar(
  101. centerTitle: "视频详情",
  102. actions: <Widget>[
  103. _hasData && detailObj.checkFlag==0?FlatButton(
  104. child: Text(
  105. "编辑",
  106. style: TextStyle(
  107. color: Colors.white, fontSize: ScreenUtil().setSp(15)),
  108. ),
  109. textColor: Colours.dark_text,
  110. highlightColor: Colors.transparent,
  111. onPressed: () {
  112. // NavigatorUtils.push(context, WodeRouter.videoUpload);
  113. if(_controller!=null){
  114. _controller.pause();
  115. }
  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. }