video_detail.dart 14 KB

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