video_detail.dart 25 KB

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