video_detail.dart 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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 'package:liftmanager/utils/fast_notification.dart';
  22. import 'dart:convert';
  23. import 'package:shared_preferences/shared_preferences.dart';
  24. import 'package:liftmanager/utils/utils.dart';
  25. import 'dart:math';
  26. import 'package:liftmanager/internal/account/account_router.dart';
  27. import 'package:flustars/flustars.dart' as FlutterStars;
  28. import 'package:liftmanager/common/common.dart';
  29. import 'package:flutter/services.dart';
  30. import 'package:orientation/orientation.dart';
  31. class VideoDetail extends StatefulWidget {
  32. VideoDetail(this.id);
  33. final String id;
  34. @override
  35. State<StatefulWidget> createState() {
  36. return VideoDetailState();
  37. }
  38. }
  39. class VideoDetailState extends State<VideoDetail> {
  40. @override
  41. void initState() {
  42. super.initState();
  43. // getVideoDetail();
  44. Future.delayed(Duration(milliseconds: 100),(){
  45. getVideoDetail();
  46. });
  47. }
  48. bool _hasData = false;
  49. VideoDetailModel detailObj;
  50. // var _storageLikeId;
  51. // var _storageFavId;
  52. VideoPlayerController _controller;
  53. Future getVideoDetail() async {
  54. if(_controller != null){
  55. _controller.pause();
  56. _controller = null;
  57. }
  58. print("-/-/-/-////////////////////////-----------");
  59. await NewApiService().getVideoDetail(int.parse(widget.id), 1,
  60. onSuccess: (res) {
  61. if (res != null) {
  62. _hasData = true;
  63. detailObj = res;
  64. _controller = VideoPlayerController.network(
  65. Utils.getImagePath(detailObj.url)
  66. // imgFontUrl + detailObj.url
  67. );
  68. // player.setDataSource(detailObj.url, autoPlay: false,showCover: true);
  69. // player.addListener(_fijkValueListener);
  70. setState(() {});
  71. }
  72. }, onError: (code, msg) {
  73. toasts(msg);
  74. });
  75. }
  76. Future changeLike(type) async {
  77. await NewApiService().videoLike(detailObj.id, type, 1, onSuccess: (res) {
  78. // if (res != null) {
  79. // // saveLikeId(res.id,type);
  80. // }
  81. String textLike;
  82. if (type == 2) {
  83. textLike = "点赞";
  84. } else if (type == 3) {
  85. textLike = "收藏";
  86. initCollect();
  87. }
  88. toasts("$textLike成功");
  89. getVideoDetail();
  90. }, onError: (code, msg) {
  91. toasts(msg);
  92. });
  93. }
  94. showAlertEvent(){
  95. showAlert(
  96. context,
  97. "提示",
  98. "确定登录?",
  99. "确定",
  100. () {
  101. NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  102. },
  103. txt2: "取消",
  104. onPre2: () {
  105. NavigatorUtils.goBack(context);
  106. },
  107. );
  108. }
  109. Future cancelLike(type) async {
  110. // _storageFavId
  111. // _storageLikeId
  112. var idChiose;
  113. String textLike;
  114. if (type == 2) {
  115. idChiose = detailObj.likeId;
  116. textLike = "点赞";
  117. } else if (type == 3) {
  118. idChiose = detailObj.favoriteId;
  119. textLike = "收藏";
  120. }
  121. await NewApiService().videoLikeCancel(idChiose, onSuccess: (res) {
  122. toasts("取消$textLike成功");
  123. if(type == 3){
  124. initCollect();
  125. }
  126. getVideoDetail();
  127. }, onError: (code, msg) {
  128. toasts(msg);
  129. });
  130. }
  131. initCollect(){
  132. String collectInit = randomInt(1111,9999).toString() + DateTime.now().millisecondsSinceEpoch.toString();
  133. FastNotification.push("collectAction",collectInit);
  134. }
  135. randomInt(int min, int max) {
  136. return new Random().nextInt(max) % (max - min + 1) + min;
  137. }
  138. @override
  139. void dispose() {
  140. _controller.pause();
  141. _controller.dispose();
  142. // SystemChrome.setPreferredOrientations([
  143. // DeviceOrientation.portraitUp,
  144. // ]);
  145. // OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  146. // player.release();
  147. // player.removeListener(_fijkValueListener);
  148. super.dispose();
  149. }
  150. @override
  151. Widget build(BuildContext context) {
  152. double width = MediaQuery.of(context).size.width;
  153. double height = MediaQuery.of(context).size.height;
  154. print(width);
  155. print(height);
  156. print(12345678);
  157. if(width > height){
  158. // SystemChrome.setPreferredOrientations([
  159. // DeviceOrientation.portraitUp,
  160. // ]);
  161. OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  162. }
  163. return Scaffold(
  164. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  165. appBar: MyAppBar(
  166. centerTitle: "电梯学堂",
  167. ),
  168. body: _hasData
  169. ? Stack(
  170. children: <Widget>[
  171. Container(
  172. child: ListView(children: <Widget>[
  173. Column(
  174. mainAxisAlignment: MainAxisAlignment.start,
  175. crossAxisAlignment: CrossAxisAlignment.start,
  176. children: <Widget>[
  177. Container(
  178. padding: EdgeInsets.only(
  179. left: ScreenUtil().setWidth(15),
  180. right: ScreenUtil().setWidth(15),
  181. top: ScreenUtil().setWidth(15)),
  182. child: ClipRRect(
  183. borderRadius: BorderRadius.circular(5),
  184. child:
  185. new Chewie(
  186. controller: ChewieController(
  187. videoPlayerController:
  188. // VideoPlayerController.network(
  189. // imgFontUrl + detailObj.url
  190. // ),
  191. _controller,
  192. aspectRatio: 3 / 2,
  193. allowFullScreen:true,
  194. autoPlay: false,
  195. looping: true,
  196. // startAt: Duration(seconds: 1,minutes: 1),
  197. showControls: true,
  198. deviceOrientationsAfterFullScreen:[DeviceOrientation.portraitUp],
  199. // 占位图
  200. // placeholder: Image.network(
  201. // imgFontUrl+detailObj.cover,
  202. // fit: BoxFit.contain,
  203. // ),
  204. // 是否在 UI 构建的时候就加载视频
  205. autoInitialize: true,
  206. // 拖动条样式颜色
  207. materialProgressColors:
  208. new ChewieProgressColors(
  209. playedColor: Colors.red,
  210. handleColor: Colors.blue,
  211. backgroundColor: Colors.grey,
  212. bufferedColor: Colors.lightGreen,
  213. ),
  214. ),
  215. ),
  216. )
  217. ),
  218. Container(
  219. width: width,
  220. padding: EdgeInsets.only(
  221. left: ScreenUtil().setWidth(15),
  222. right: ScreenUtil().setWidth(15),
  223. top: ScreenUtil().setWidth(10),
  224. bottom: ScreenUtil().setWidth(10)),
  225. decoration: BoxDecoration(
  226. border: Border(
  227. bottom: BorderSide(width: 0.5, color: Colours.line),
  228. ),
  229. ),
  230. child: Row(
  231. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  232. crossAxisAlignment: CrossAxisAlignment.start,
  233. children:<Widget>[
  234. Column(
  235. mainAxisAlignment: MainAxisAlignment.start,
  236. crossAxisAlignment: CrossAxisAlignment.start,
  237. children: <Widget>[
  238. Container(
  239. width: width*0.65,
  240. child: Text(
  241. detailObj.title??"",
  242. style: TextStyle(
  243. fontSize: ScreenUtil().setSp(16)),
  244. textAlign: TextAlign.start,
  245. maxLines: 1,
  246. overflow: TextOverflow.ellipsis,
  247. ),
  248. ),
  249. Text(
  250. detailObj.brandName??"",
  251. style: TextStyle(
  252. color: Color(0xff666666),
  253. fontSize: ScreenUtil().setSp(14)),
  254. textAlign: TextAlign.start,
  255. ),
  256. ]
  257. ),
  258. Row(
  259. children: <Widget>[
  260. Row(
  261. crossAxisAlignment: CrossAxisAlignment.start,
  262. children: <Widget>[
  263. Text(
  264. "${detailObj.likeNum??"0"}",
  265. style: TextStyle(
  266. color: Color(0xff999999),
  267. fontSize: ScreenUtil().setSp(14)),
  268. textAlign: TextAlign.start,
  269. ),
  270. SizedBox(
  271. width:3
  272. ),
  273. Icon(
  274. IconData(0xe7cd,
  275. fontFamily: "myfont"),
  276. size: 14.0,
  277. color: Color(0xff999999),
  278. ),
  279. ],
  280. ),
  281. SizedBox(
  282. width:15
  283. ),
  284. Row(
  285. crossAxisAlignment: CrossAxisAlignment.start,
  286. children: <Widget>[
  287. Text(
  288. "${detailObj.browseNum??"0"}",
  289. style: TextStyle(
  290. color: Color(0xff999999),
  291. fontSize: ScreenUtil().setSp(14)),
  292. textAlign: TextAlign.start,
  293. ),
  294. SizedBox(
  295. width:3
  296. ),
  297. Icon(
  298. IconData(0xe610,
  299. fontFamily: "myfont"),
  300. size: 14.0,
  301. color: Color(0xff999999),
  302. ),
  303. ],
  304. ),
  305. ],
  306. ),
  307. // Text(
  308. // detailObj.likeNum!=null?detailObj.likeNum.toString() + "赞":"0赞",
  309. // style: TextStyle(
  310. // color: Color(0xff999999),
  311. // fontSize: ScreenUtil().setSp(14)),
  312. // textAlign: TextAlign.start,
  313. // ),
  314. ]
  315. )
  316. ),
  317. Container(
  318. padding: EdgeInsets.only(
  319. left: ScreenUtil().setWidth(15),
  320. top: ScreenUtil().setWidth(30),
  321. bottom: ScreenUtil().setWidth(30)),
  322. decoration: BoxDecoration(
  323. border: Border(
  324. bottom: BorderSide(width: 0.5, color: Colours.line),
  325. ),
  326. ),
  327. child: Row(
  328. children: <Widget>[
  329. Container(
  330. child: ClipRRect(
  331. borderRadius: BorderRadius.circular(
  332. ScreenUtil().setWidth(18)),
  333. child: LoadNetworkImage(
  334. detailObj.avatarUrl,
  335. // fit: BoxFit.cover,
  336. width: ScreenUtil().setWidth(36),
  337. height: ScreenUtil().setWidth(36),
  338. ),
  339. )),
  340. Container(
  341. padding: EdgeInsets.only(left: 5),
  342. child: Column(
  343. crossAxisAlignment: CrossAxisAlignment.start,
  344. children: <Widget>[
  345. Text(
  346. detailObj.nickname??"",
  347. style: TextStyle(
  348. fontSize: ScreenUtil().setSp(14),
  349. color: Color(0xff666666)),
  350. ),
  351. Text(
  352. detailObj.createTime!=null?DateUtils.instance.getFormartData(
  353. timeSamp: detailObj.createTime,
  354. format: "yyyy-MM-dd"):"",
  355. style: TextStyle(
  356. fontSize: ScreenUtil().setSp(12),
  357. color: Color(0xffaaaaaa)),
  358. ),
  359. ],
  360. ),
  361. )
  362. ],
  363. ),
  364. ),
  365. Column(
  366. crossAxisAlignment: CrossAxisAlignment.start,
  367. mainAxisAlignment: MainAxisAlignment.start,
  368. children: <Widget>[
  369. Container(
  370. padding: EdgeInsets.only(
  371. left: ScreenUtil().setWidth(15),
  372. top: ScreenUtil().setWidth(10),
  373. bottom: ScreenUtil().setWidth(5)),
  374. child: Text(
  375. "视频简介",
  376. style: TextStyle(
  377. fontSize: ScreenUtil().setSp(16),
  378. ),
  379. textAlign: TextAlign.left,
  380. ),
  381. ),
  382. Container(
  383. padding: EdgeInsets.only(
  384. left: ScreenUtil().setWidth(15),
  385. right: ScreenUtil().setWidth(15),
  386. top: ScreenUtil().setWidth(10),
  387. bottom: ScreenUtil().setWidth(90)),
  388. child: Text(
  389. detailObj.descr??"",
  390. style: TextStyle(
  391. color: Color(0xff666666),
  392. fontSize: ScreenUtil().setSp(14),
  393. ),
  394. textAlign: TextAlign.left,
  395. ),
  396. ),
  397. ],
  398. ),
  399. ],
  400. ),
  401. ])),
  402. Positioned(
  403. bottom: 0,
  404. left: 0,
  405. child: Container(
  406. width: width,
  407. child: Row(children: <Widget>[
  408. Container(
  409. height: 70,
  410. width: width / 2,
  411. color: Colors.white,
  412. padding: EdgeInsets.only(
  413. left: ScreenUtil().setWidth(10),
  414. right: ScreenUtil().setWidth(10),
  415. top: ScreenUtil().setWidth(10)),
  416. child: Row(
  417. mainAxisAlignment:
  418. MainAxisAlignment.spaceAround,
  419. children: <Widget>[
  420. GestureDetector(
  421. onTap: () {
  422. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  423. showAlertEvent();
  424. }else {
  425. if (detailObj.isLike == 1) {
  426. cancelLike(2);
  427. } else {
  428. changeLike(2);
  429. }
  430. }
  431. },
  432. child: Container(
  433. child: Column(children: <Widget>[
  434. Icon(
  435. IconData(
  436. detailObj.isLike == 1
  437. ? 0xe63c
  438. : 0xe608,
  439. fontFamily: "myfont"),
  440. size: 26.0,
  441. color: Color(detailObj.isLike == 1
  442. ? 0xff0388FD
  443. : 0xff333333),
  444. ),
  445. Text(
  446. detailObj.isLike == 1 ? "已点赞" : "点赞",
  447. style: TextStyle(
  448. color: Color(detailObj.isLike == 1
  449. ? 0xff0388FD
  450. : 0xff000000),
  451. fontSize: ScreenUtil().setSp(14)),
  452. textAlign: TextAlign.start,
  453. ),
  454. ])),
  455. ),
  456. GestureDetector(
  457. onTap: () {
  458. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  459. showAlertEvent();
  460. }else {
  461. if (detailObj.isFavorite == 1) {
  462. cancelLike(3);
  463. } else {
  464. changeLike(3);
  465. }
  466. }
  467. },
  468. child: Container(
  469. child: Column(children: <Widget>[
  470. Icon(
  471. IconData(
  472. detailObj.isFavorite == 1
  473. ? 0xe654
  474. : 0xe604,
  475. fontFamily: "myfont"),
  476. size: 26.0,
  477. color: Color(detailObj.isFavorite == 1
  478. ? 0xff0388FD
  479. : 0xff333333),
  480. ),
  481. Text(
  482. detailObj.isFavorite == 1
  483. ? "已收藏"
  484. : "收藏",
  485. style: TextStyle(
  486. color: Color(
  487. detailObj.isFavorite == 1
  488. ? 0xff0388FD
  489. : 0xff000000),
  490. fontSize: ScreenUtil().setSp(14)),
  491. textAlign: TextAlign.start,
  492. ),
  493. ])),
  494. )
  495. ],
  496. )),
  497. Container(
  498. height: ScreenUtil().setWidth(70),
  499. width: width / 2,
  500. color: Color(0xff0388FD),
  501. child: FlatButton(
  502. // padding: EdgeInsets.all(15.0),
  503. child: Text(
  504. "打赏",
  505. style:
  506. TextStyle(fontSize: ScreenUtil().setSp(16)),
  507. ),
  508. textColor: Colors.white,
  509. onPressed: () {
  510. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  511. showAlertEvent();
  512. }else {
  513. var nickname;
  514. if(detailObj.nickname!=null){
  515. nickname = Uri.encodeComponent(detailObj.nickname);
  516. }
  517. NavigatorUtils.push(
  518. context, "${BbsRouter.questionPay}?id=${detailObj.id}&type=video&name=$nickname");
  519. }
  520. },
  521. ),
  522. ),
  523. ])))
  524. ],
  525. )
  526. : Center(
  527. child: Text("正在加载..."),
  528. ),
  529. );
  530. }
  531. }