video_detail.dart 13 KB

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