video_detail.dart 24 KB

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