video_detail.dart 25 KB

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