video_detail.dart 26 KB

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