question_detail.dart 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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 'dart:convert';
  17. import 'package:liftmanager/utils/url.dart';
  18. import 'package:liftmanager/utils/time_format.dart';
  19. import 'package:liftmanager/internal/bbs/model/question_detail.dart';
  20. import 'package:liftmanager/utils/fast_notification.dart';
  21. import 'dart:math';
  22. import 'package:liftmanager/widgets/preview_images.dart';
  23. import 'package:liftmanager/utils/utils.dart';
  24. import 'package:liftmanager/utils/theme_utils.dart';
  25. import 'package:liftmanager/internal/account/account_router.dart';
  26. import 'package:flustars/flustars.dart' as FlutterStars;
  27. import 'package:liftmanager/common/common.dart';
  28. class QuestionDetail extends StatefulWidget {
  29. QuestionDetail(this.id);
  30. final String id;
  31. @override
  32. State<StatefulWidget> createState() {
  33. return QuestionDetailState();
  34. }
  35. }
  36. class QuestionDetailState extends State<QuestionDetail> {
  37. @override
  38. void initState() {
  39. super.initState();
  40. getQuestionDetail();
  41. FastNotification.addListener("initIsPay", (initThisUserMoney) {
  42. if (mounted) {
  43. getQuestionDetail();
  44. setState(() {
  45. });
  46. }
  47. });
  48. }
  49. bool _hasData = false;
  50. QuestionDetailModel detailObj;
  51. List<String> listPreview = [];
  52. Future getQuestionDetail() async {
  53. await NewApiService().getQuestionDetail(int.parse(widget.id),
  54. onSuccess: (res) {
  55. // print(jsonEncode(res));
  56. // print(123456);
  57. if (res != null) {
  58. _hasData = true;
  59. detailObj = res;
  60. setState(() {
  61. });
  62. listPreview = [];
  63. detailObj.imgs.split(",").forEach((element) {
  64. listPreview.add(Utils.getImagePath(element,isWater: true));
  65. });
  66. // print(123456);
  67. // print(jsonEncode(res));
  68. // print(jsonEncode(detailObj.title));
  69. // print(1234563333);
  70. }
  71. }, onError: (code, msg) {
  72. toasts(msg);
  73. });
  74. }
  75. showAlertEvent(){
  76. showAlert(
  77. context,
  78. "提示",
  79. "确定登录?",
  80. "确定",
  81. () {
  82. NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  83. },
  84. txt2: "取消",
  85. onPre2: () {
  86. NavigatorUtils.goBack(context);
  87. },
  88. );
  89. }
  90. Future changeLike() async {
  91. await NewApiService().questionLike(detailObj.id, 1, onSuccess: (res) {
  92. toasts("点赞成功");
  93. getQuestionDetail();
  94. }, onError: (code, msg) {
  95. toasts(msg);
  96. });
  97. }
  98. Future changeFav() async {
  99. await NewApiService().questionFav(detailObj.id, 1, onSuccess: (res) {
  100. toasts("收藏成功");
  101. initCollect();
  102. getQuestionDetail();
  103. }, onError: (code, msg) {
  104. toasts(msg);
  105. });
  106. }
  107. Future cancelLike() async {
  108. await NewApiService().questionLikeCancel(detailObj.id,1, onSuccess: (res) {
  109. toasts("取消点赞成功");
  110. getQuestionDetail();
  111. }, onError: (code, msg) {
  112. toasts(msg);
  113. });
  114. }
  115. Future cancelFav() async {
  116. await NewApiService().questionFavCancel(detailObj.id,1, onSuccess: (res) {
  117. toasts("取消收藏成功");
  118. initCollect();
  119. getQuestionDetail();
  120. }, onError: (code, msg) {
  121. toasts(msg);
  122. });
  123. }
  124. initCollect(){
  125. String collectInit = randomInt(1111,9999).toString() + DateTime.now().millisecondsSinceEpoch.toString();
  126. FastNotification.push("collectAction",collectInit);
  127. }
  128. randomInt(int min, int max) {
  129. return new Random().nextInt(max) % (max - min + 1) + min;
  130. }
  131. @override
  132. Widget build(BuildContext context) {
  133. double width = MediaQuery.of(context).size.width;
  134. return Scaffold(
  135. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  136. appBar: MyAppBar(
  137. centerTitle: "问题详情",
  138. ),
  139. body: _hasData?Stack(
  140. children: <Widget>[
  141. Container(
  142. child: ListView(children: <Widget>[
  143. Column(
  144. mainAxisAlignment: MainAxisAlignment.start,
  145. crossAxisAlignment: CrossAxisAlignment.start,
  146. children: <Widget>[
  147. Container(
  148. width: width,
  149. padding: EdgeInsets.only(
  150. left: ScreenUtil().setWidth(15),
  151. right: ScreenUtil().setWidth(15),
  152. top: ScreenUtil().setWidth(10),
  153. bottom: ScreenUtil().setWidth(10)),
  154. decoration: BoxDecoration(
  155. border: Border(
  156. bottom: BorderSide(width: 0.5, color: Colours.line),
  157. ),
  158. ),
  159. child: Column(
  160. mainAxisAlignment: MainAxisAlignment.start,
  161. crossAxisAlignment: CrossAxisAlignment.start,
  162. children: <Widget>[
  163. Text(
  164. detailObj.title??"",
  165. style: TextStyle(
  166. fontSize: ScreenUtil().setSp(16)),
  167. textAlign: TextAlign.start,
  168. maxLines: 1,
  169. overflow: TextOverflow.ellipsis,
  170. ),
  171. Row(
  172. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  173. children: <Widget>[
  174. Text(
  175. detailObj.brandName??"",
  176. style: TextStyle(
  177. color: Color(0xff666666),
  178. fontSize: ScreenUtil().setSp(14)),
  179. textAlign: TextAlign.start,
  180. ),
  181. Row(
  182. children: <Widget>[
  183. Row(
  184. crossAxisAlignment: CrossAxisAlignment.start,
  185. children: <Widget>[
  186. Text(
  187. "${detailObj.likeNum??"0"}",
  188. style: TextStyle(
  189. color: Color(0xff999999),
  190. fontSize: ScreenUtil().setSp(14)),
  191. textAlign: TextAlign.start,
  192. ),
  193. SizedBox(
  194. width:3
  195. ),
  196. Icon(
  197. IconData(0xe7cd,
  198. fontFamily: "myfont"),
  199. size: 14.0,
  200. color: Color(0xff999999),
  201. ),
  202. ],
  203. ),
  204. SizedBox(
  205. width:15
  206. ),
  207. Row(
  208. crossAxisAlignment: CrossAxisAlignment.start,
  209. children: <Widget>[
  210. Text(
  211. "${detailObj.browseNum??"0"}",
  212. style: TextStyle(
  213. color: Color(0xff999999),
  214. fontSize: ScreenUtil().setSp(14)),
  215. textAlign: TextAlign.start,
  216. ),
  217. SizedBox(
  218. width:3
  219. ),
  220. Icon(
  221. IconData(0xe610,
  222. fontFamily: "myfont"),
  223. size: 14.0,
  224. color: Color(0xff999999),
  225. ),
  226. ],
  227. ),
  228. ],
  229. ),
  230. ],
  231. )
  232. ]),
  233. ),
  234. Container(
  235. padding: EdgeInsets.only(
  236. left: ScreenUtil().setWidth(15),
  237. top: ScreenUtil().setWidth(30),
  238. bottom: ScreenUtil().setWidth(30)),
  239. decoration: BoxDecoration(
  240. border: Border(
  241. bottom: BorderSide(width: 0.5, color: Colours.line),
  242. ),
  243. ),
  244. child: Row(
  245. children: <Widget>[
  246. Container(
  247. child: ClipRRect(
  248. borderRadius: BorderRadius.circular(
  249. ScreenUtil().setWidth(18)),
  250. child: LoadNetworkImage(
  251. detailObj.avatarUrl,
  252. // fit: BoxFit.cover,
  253. width: ScreenUtil().setWidth(36),
  254. height: ScreenUtil().setWidth(36),
  255. ),
  256. )),
  257. Container(
  258. padding: EdgeInsets.only(left: 5),
  259. child: Column(
  260. crossAxisAlignment: CrossAxisAlignment.start,
  261. children: <Widget>[
  262. Text(
  263. detailObj.userName??"",
  264. style: TextStyle(
  265. fontSize: ScreenUtil().setSp(14),
  266. ),
  267. ),
  268. Text(
  269. DateUtils.instance.getFormartData(
  270. timeSamp: detailObj.createTime,
  271. format: "yyyy-MM-dd"),
  272. style: TextStyle(
  273. fontSize: ScreenUtil().setSp(12),
  274. color: Color(0xffaaaaaa)),
  275. ),
  276. ],
  277. ),
  278. )
  279. ],
  280. ),
  281. ),
  282. Column(
  283. crossAxisAlignment: CrossAxisAlignment.start,
  284. mainAxisAlignment: MainAxisAlignment.start,
  285. children: <Widget>[
  286. Container(
  287. padding: EdgeInsets.only(
  288. left: ScreenUtil().setWidth(15),
  289. top: ScreenUtil().setWidth(10),
  290. bottom: ScreenUtil().setWidth(5)),
  291. child: Text(
  292. "问题描述",
  293. style: TextStyle(
  294. fontSize: ScreenUtil().setSp(16),
  295. ),
  296. textAlign: TextAlign.left,
  297. ),
  298. ),
  299. Container(
  300. padding: EdgeInsets.only(
  301. left: ScreenUtil().setWidth(15),
  302. top: ScreenUtil().setWidth(10),
  303. bottom: ScreenUtil().setWidth(50)),
  304. child: Text(
  305. detailObj.expression??"",
  306. style: TextStyle(
  307. fontSize: ScreenUtil().setSp(14),
  308. ),
  309. textAlign: TextAlign.left,
  310. ),
  311. ),
  312. ],
  313. ),
  314. SizedBox(
  315. height: 6,
  316. child: Container(color: ThemeUtils.getDialogTextFieldColor(context)),
  317. ),
  318. Column(
  319. crossAxisAlignment: CrossAxisAlignment.start,
  320. mainAxisAlignment: MainAxisAlignment.start,
  321. children: <Widget>[
  322. Container(
  323. padding: EdgeInsets.only(
  324. left: ScreenUtil().setWidth(15),
  325. top: ScreenUtil().setWidth(10),
  326. bottom: ScreenUtil().setWidth(5)),
  327. child: Text(
  328. "解决方法",
  329. style: TextStyle(
  330. fontSize: ScreenUtil().setSp(16),
  331. ),
  332. textAlign: TextAlign.left,
  333. ),
  334. ),
  335. detailObj.isTip==1?Container(
  336. padding: EdgeInsets.only(
  337. left: ScreenUtil().setWidth(15),
  338. right: ScreenUtil().setWidth(15),
  339. top: ScreenUtil().setWidth(10),
  340. bottom: ScreenUtil().setWidth(50)),
  341. child: Text(
  342. detailObj.solution??"",
  343. style: TextStyle(
  344. fontSize: ScreenUtil().setSp(14),
  345. ),
  346. textAlign: TextAlign.left,
  347. ),
  348. ):Container(
  349. padding: EdgeInsets.only(left: ScreenUtil().setWidth(15),bottom: ScreenUtil().setWidth(20)),
  350. child:Row(
  351. mainAxisAlignment: MainAxisAlignment.center,
  352. children: <Widget>[
  353. ClipRRect(
  354. borderRadius: BorderRadius.circular(20),
  355. child: Container(
  356. padding: EdgeInsets.only(left:10,right:10,top:2,bottom:5),
  357. color: Color(0xffffae01),
  358. child: Text(
  359. "打赏后可查看全部",
  360. style: TextStyle(
  361. fontSize: ScreenUtil().setSp(14),
  362. color: Colors.white
  363. ),
  364. textAlign: TextAlign.left,
  365. ),
  366. )
  367. )
  368. ],
  369. )
  370. ),
  371. ],
  372. ),
  373. detailObj.isTip==1?Container(
  374. padding: EdgeInsets.only(
  375. top: ScreenUtil().setWidth(5),
  376. left: ScreenUtil().setWidth(15),
  377. right: ScreenUtil().setWidth(15)),
  378. child: Wrap(
  379. spacing: 6,
  380. alignment: WrapAlignment.spaceBetween,
  381. crossAxisAlignment: WrapCrossAlignment.center,
  382. children: detailObj.imgs !=
  383. null &&
  384. detailObj.imgs
  385. .isNotEmpty
  386. ? List<Widget>.from(detailObj.imgs
  387. .split(",")
  388. .asMap().keys.map((subindex) {
  389. // print(item);
  390. return Container(
  391. padding:subindex<detailObj.imgs.split(",").length-1?EdgeInsets.only(right:6):EdgeInsets.only(right:0),
  392. // color:Colors.red,
  393. // decoration: BoxDecoration(
  394. // borderRadius: BorderRadius.circular(20.0),
  395. // ),
  396. child: GestureDetector(
  397. onTap: (){
  398. Navigator.of(context).push(
  399. new FadeRoute(
  400. page: PhotoViewGalleryScreen(
  401. images: listPreview, //传入图片list
  402. index: subindex, //传入当前点击的图片的index
  403. // heroTag: img,//传入当前点击的图片的hero tag (可选)
  404. ),
  405. ),
  406. );
  407. },
  408. child: ClipRRect(
  409. borderRadius:
  410. BorderRadius.circular(
  411. 10),
  412. child: LoadNetworkImage(
  413. detailObj.imgs.split(",")[subindex],
  414. // height: width/375*75,
  415. height: ScreenUtil()
  416. .setWidth(80),
  417. width: ScreenUtil()
  418. .setWidth(80),
  419. isWater: true,
  420. ),
  421. ),
  422. ),
  423. );
  424. }).toList())
  425. : <Widget>[]
  426. )):Container(child:null),
  427. SizedBox(
  428. height: 70,
  429. ),
  430. ],
  431. ),
  432. ])),
  433. Positioned(
  434. bottom: 0,
  435. left: 0,
  436. child: Container(
  437. width: width,
  438. child: Row(children: <Widget>[
  439. Container(
  440. height: ScreenUtil().setWidth(70),
  441. width: width / 2,
  442. color: Colors.white,
  443. padding: EdgeInsets.only(
  444. // left: ScreenUtil().setWidth(10),
  445. // right: ScreenUtil().setWidth(10),
  446. top: ScreenUtil().setWidth(10)),
  447. child: Row(
  448. mainAxisAlignment:
  449. MainAxisAlignment.center,
  450. children: <Widget>[
  451. Container(
  452. width: 1/4*width,
  453. child: GestureDetector(
  454. onTap: () {
  455. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  456. showAlertEvent();
  457. }else {
  458. if (detailObj.isLike == 1) {
  459. // cancelLike(2);
  460. cancelLike();
  461. } else {
  462. // changeLike(2);
  463. changeLike();
  464. }
  465. }
  466. },
  467. child: Row(
  468. children: <Widget>[
  469. Column(children: <Widget>[
  470. Icon(
  471. IconData(
  472. detailObj.isLike == 1
  473. ? 0xe63c
  474. : 0xe608,
  475. fontFamily: "myfont"),
  476. size: 26.0,
  477. color: Color(detailObj.isLike == 1
  478. ? 0xff0388FD
  479. : 0xff333333),
  480. ),
  481. Text(
  482. detailObj.isLike == 1 ? "已点赞" : "点赞",
  483. style: TextStyle(
  484. color: Color(detailObj.isLike == 1
  485. ? 0xff0388FD
  486. : 0xff000000),
  487. fontSize: ScreenUtil().setSp(14)),
  488. textAlign: TextAlign.start,
  489. ),
  490. ])
  491. ],
  492. )
  493. ),
  494. ),
  495. GestureDetector(
  496. onTap: () {
  497. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  498. showAlertEvent();
  499. }else {
  500. if (detailObj.isFavorite == 1) {
  501. // cancelLike(3);
  502. cancelFav();
  503. } else {
  504. // changeLike(3);
  505. changeFav();
  506. }
  507. }
  508. },
  509. child: Container(
  510. child: Column(children: <Widget>[
  511. Icon(
  512. IconData(
  513. detailObj.isFavorite == 1
  514. ? 0xe654
  515. : 0xe604,
  516. fontFamily: "myfont"),
  517. size: 26.0,
  518. color: Color(detailObj.isFavorite == 1
  519. ? 0xff0388FD
  520. : 0xff333333),
  521. ),
  522. Text(
  523. detailObj.isFavorite == 1
  524. ? "已收藏"
  525. : "收藏",
  526. style: TextStyle(
  527. color: Color(
  528. detailObj.isFavorite == 1
  529. ? 0xff0388FD
  530. : 0xff000000),
  531. fontSize: ScreenUtil().setSp(14)),
  532. textAlign: TextAlign.start,
  533. ),
  534. ])),
  535. ),
  536. ],
  537. )),
  538. Container(
  539. height: ScreenUtil().setWidth(70),
  540. width: width / 2,
  541. color: Color(0xff0388FD),
  542. child: FlatButton(
  543. // padding: EdgeInsets.all(15.0),
  544. child: Text(
  545. "打赏",
  546. style:
  547. TextStyle(fontSize: ScreenUtil().setSp(16)),
  548. ),
  549. textColor: Colors.white,
  550. onPressed: () {
  551. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  552. showAlertEvent();
  553. }else {
  554. NavigatorUtils.push(
  555. context, "${BbsRouter.questionPay}?id=${detailObj.id}&type=question&name=${Uri.encodeComponent(detailObj.userName)}");
  556. }
  557. },
  558. ),
  559. ),
  560. ])))
  561. ],
  562. )
  563. : Center(
  564. child: Text("正在加载..."),
  565. ),
  566. );
  567. }
  568. }
  569. class FadeRoute extends PageRouteBuilder {
  570. final Widget page;
  571. FadeRoute({this.page})
  572. : super(
  573. pageBuilder: (
  574. BuildContext context,
  575. Animation<double> animation,
  576. Animation<double> secondaryAnimation,
  577. ) =>
  578. page,
  579. transitionsBuilder: (
  580. BuildContext context,
  581. Animation<double> animation,
  582. Animation<double> secondaryAnimation,
  583. Widget child,
  584. ) =>
  585. FadeTransition(
  586. opacity: animation,
  587. child: child,
  588. ),
  589. );
  590. }