video_detail.dart 13 KB

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