Hibok
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

586 righe
19 KiB

  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:chat/data/constants.dart';
  3. import 'package:chat/generated/i18n.dart';
  4. import 'package:chat/home/InformUser.dart';
  5. import 'package:chat/models/ref_name_provider.dart';
  6. import 'package:chat/utils/CustomUI.dart';
  7. import 'package:chat/utils/MessageBox.dart';
  8. import 'package:chat/utils/MessageMgr.dart';
  9. import 'package:chat/utils/PicSwiper.dart';
  10. import 'package:chat/utils/app_navigator.dart';
  11. import 'package:chat/utils/msgHandler.dart';
  12. import 'package:flutter/material.dart';
  13. import 'package:oktoast/oktoast.dart';
  14. import 'package:provider/provider.dart';
  15. import '../utils/HttpUtil.dart';
  16. import 'package:dio/dio.dart';
  17. import "../data/UserData.dart";
  18. import '../utils/TokenMgr.dart';
  19. class ProgramDetailPage extends StatefulWidget {
  20. @required
  21. final int programId;
  22. ProgramDetailPage({Key key, this.programId}) : super(key: key);
  23. @override
  24. _ProgramDetailPageState createState() => new _ProgramDetailPageState();
  25. }
  26. class _ProgramDetailPageState extends State<ProgramDetailPage> {
  27. GlobalKey<ScaffoldState> registKey = new GlobalKey();
  28. List fabulousList = [];
  29. bool isMyself = false;
  30. List evaluateList = [];
  31. List enrollList = [];
  32. bool showAllContent = false;
  33. bool isMan = false;
  34. bool isProgram = false;
  35. Map programInfo = {};
  36. bool isLoadingFish = false;
  37. bool isNonContent = false;
  38. bool isJoin = false;
  39. msgRefresh(data) {
  40. getData();
  41. }
  42. msgUpdateDy(data) {
  43. setState(() {
  44. isNonContent = data;
  45. });
  46. }
  47. @override
  48. void initState() {
  49. super.initState();
  50. MessageMgr().on('delete_program', msgDeleteProgram);
  51. MessageMgr().on('update_dy', msgUpdateDy);
  52. MessageMgr().on('refresh_list', msgRefreshList);
  53. getData();
  54. }
  55. msgRefreshList(data) {
  56. getData();
  57. }
  58. msgDeleteProgram(data) {
  59. Navigator.of(context).pop();
  60. }
  61. Future getData() async {
  62. Map data = {
  63. "userId": UserData().basicInfo.userId,
  64. "id": widget.programId,
  65. };
  66. data['sign'] = TokenMgr().getSign(data);
  67. Response res = await HttpUtil().post('station/evaluate/detail',
  68. data: data, failback: () => Navigator.of(context).pop());
  69. var resData = res.data;
  70. print(resData);
  71. if (resData['code'] == 0) {
  72. if (resData['data']['FabulousList'] != null)
  73. fabulousList = resData['data']['FabulousList'];
  74. if (resData['data']['EvaluateList'] != null) {
  75. evaluateList = resData['data']['EvaluateList'];
  76. }
  77. enrollList = resData['data']['EnrollList'];
  78. isMyself = resData['data']['UserId'] == UserData().basicInfo.userId;
  79. isMan = resData['data']['Sex'] == 1;
  80. isProgram = resData['data']['Type'] == 0;
  81. programInfo = resData['data'];
  82. programInfo['Id'] = widget.programId;
  83. isNonContent = resData['data']['EvaluateStatus'] == 1;
  84. isJoin = resData['data']['IsEnroll'] == 1;
  85. isLoadingFish = true;
  86. setState(() {});
  87. } else {
  88. showToast(resData['msg']);
  89. }
  90. }
  91. @override
  92. Widget build(BuildContext context) {
  93. Widget appBar = new AppBar(
  94. //backgroundColor: AppColors.NewAppbarBgColor,
  95. title: new Text(
  96. isProgram
  97. ? I18n.of(context).program_details
  98. : I18n.of(context).dynamic_details,
  99. textScaleFactor: 1.0,
  100. style: TextStyle(color: AppColors.NewAppbarTextColor),
  101. ),
  102. elevation: 1,
  103. leading: CustomUI.buildCustomLeading(context),
  104. centerTitle: true,
  105. );
  106. var content = new Scaffold(
  107. key: registKey,
  108. appBar: appBar,
  109. //backgroundColor: Colors.white,
  110. body: SafeArea(
  111. child: Center(
  112. child: Container(
  113. height: MediaQuery.of(context).size.height,
  114. width: MediaQuery.of(context).size.width,
  115. child: _buildBody(),
  116. ),
  117. ),
  118. ));
  119. return CustomUI.buildPageLoading(context, content, !isLoadingFish);
  120. }
  121. Widget _buildBottomSheetItem(str, height, callback) {
  122. return InkWell(
  123. child: Container(
  124. height: height,
  125. decoration:
  126. BoxDecoration(border: Border(bottom: Constants.GreyBorderSide)),
  127. alignment: Alignment.center,
  128. child: Text(
  129. str,
  130. textScaleFactor: 1.0,
  131. style: TextStyle(fontSize: 18, color: Constants.BlackTextColor),
  132. ),
  133. ),
  134. onTap: callback,
  135. );
  136. }
  137. Widget _buildReply(data) {
  138. const TextColor = Constants.BlackTextColor;
  139. const BlueColor = Constants.GreyTextColor;
  140. bool isWriter =
  141. programInfo['UserId'] == UserData().basicInfo.userId; //是否发布者
  142. bool isReplyer = data['UserId'] == UserData().basicInfo.userId; //是否评论者
  143. replay() {
  144. Navigator.of(context).pop();
  145. CustomUI.showContentDialog(
  146. registKey.currentContext, programInfo['Id'], data['Pid'], 1, (data) {
  147. programInfo['EvaluateNum']++;
  148. evaluateList.add(data);
  149. setState(() {});
  150. },
  151. replyUserId: data['UserId'],
  152. replyUserName: Provider.of<RefNameProvider>(context)
  153. .getRefName(data['UserId'], data['NickName']),
  154. isMyself: isMyself);
  155. }
  156. inform() async {
  157. var resdata = {
  158. "reportuserId": UserData().basicInfo.userId,
  159. "userid": data['UserId'],
  160. };
  161. resdata['sign'] = TokenMgr().getSign(resdata);
  162. resdata['type'] = 4;
  163. resdata['objectId'] = data['Pid'];
  164. resdata['reason'] = 0;
  165. resdata["imgurl"] = '';
  166. resdata["explain"] = '';
  167. Response res = await HttpUtil().post('report/user/insert', data: resdata);
  168. Map resData = res.data;
  169. showToast(resData['msg']);
  170. if (resData['code'] == 0) {
  171. Navigator.of(context).pop();
  172. }
  173. }
  174. delete() async {
  175. var resdata = {
  176. "userId": UserData().basicInfo.userId,
  177. "pId": data['Pid'],
  178. };
  179. resdata['sign'] = TokenMgr().getSign(resdata);
  180. Response res = await HttpUtil()
  181. .post('station/delete/evaluate', data: resdata, isShowLoading: true);
  182. Map resData = res.data;
  183. if (resData['code'] == 0) {
  184. Navigator.of(context).pop();
  185. programInfo['EvaluateNum']--;
  186. getData();
  187. }
  188. }
  189. double fontSize = 14;
  190. //1.不是发布者
  191. //1.1是评论者则没有选项
  192. //1.2不是评论者则有回复和举报
  193. //2.是发布者
  194. //2.1是评论者则有删除
  195. //2.2不是评论者则有删除,回复和举报
  196. return InkWell(
  197. onTap: !isWriter && isReplyer
  198. ? null
  199. : () {
  200. double height = 50.0;
  201. List<Widget> list = [];
  202. if (!isWriter && !isReplyer)
  203. list = [
  204. _buildBottomSheetItem(
  205. I18n.of(context).reply, height, replay),
  206. _buildBottomSheetItem(
  207. I18n.of(context).report, height, inform),
  208. ];
  209. if (isWriter && isReplyer)
  210. list = [
  211. _buildBottomSheetItem(
  212. I18n.of(context).delete, height, delete),
  213. ];
  214. if (isWriter && !isReplyer)
  215. list = [
  216. _buildBottomSheetItem(
  217. I18n.of(context).delete, height, delete),
  218. _buildBottomSheetItem(
  219. I18n.of(context).reply, height, replay),
  220. _buildBottomSheetItem(
  221. I18n.of(context).report, height, inform),
  222. ];
  223. //回复不能回复自己 ,只有发布者才能删除评论
  224. showModalBottomSheet(
  225. context: registKey.currentContext,
  226. builder: (BuildContext context) {
  227. return new Container(
  228. height: height * list.length,
  229. child: Column(
  230. children: list,
  231. ),
  232. );
  233. },
  234. ).then((val) {});
  235. },
  236. child: Container(
  237. padding: EdgeInsets.only(bottom: 3),
  238. child: RichText(
  239. text: TextSpan(
  240. children: data['ReplyUserId'] == 0
  241. ? [
  242. TextSpan(
  243. text: Provider.of<RefNameProvider>(context)
  244. .getRefName(data['UserId'], data['NickName']),
  245. style: TextStyle(
  246. fontSize: fontSize,
  247. textBaseline: TextBaseline.alphabetic,
  248. color: BlueColor,
  249. fontWeight: FontWeight.w500),
  250. ),
  251. TextSpan(
  252. text: ': ${data['Content']}',
  253. style: TextStyle(
  254. color: TextColor,
  255. textBaseline: TextBaseline.alphabetic,
  256. fontSize: fontSize),
  257. )
  258. ]
  259. : [
  260. TextSpan(
  261. text: Provider.of<RefNameProvider>(context)
  262. .getRefName(data['UserId'], data['NickName']),
  263. style: TextStyle(
  264. fontSize: fontSize,
  265. textBaseline: TextBaseline.alphabetic,
  266. color: BlueColor,
  267. fontWeight: FontWeight.w500),
  268. ),
  269. TextSpan(
  270. text: ' ${I18n.of(context).reply} ',
  271. style: TextStyle(
  272. fontSize: fontSize,
  273. textBaseline: TextBaseline.alphabetic,
  274. color: TextColor,
  275. fontWeight: FontWeight.w500),
  276. ),
  277. TextSpan(
  278. text: data['ReplyNickName'],
  279. style: TextStyle(
  280. fontSize: fontSize,
  281. textBaseline: TextBaseline.alphabetic,
  282. color: BlueColor,
  283. fontWeight: FontWeight.w500),
  284. ),
  285. TextSpan(
  286. text: ': ${data['Content']}',
  287. style: TextStyle(
  288. color: TextColor,
  289. textBaseline: TextBaseline.alphabetic,
  290. fontSize: fontSize),
  291. )
  292. ]),
  293. ),
  294. ));
  295. }
  296. Widget _buildJoinItem(data) {
  297. Widget basicInfo = Row(children: <Widget>[
  298. Padding(
  299. padding: EdgeInsets.only(left: 10, right: 5),
  300. child: Stack(
  301. children: <Widget>[
  302. Padding(
  303. padding: EdgeInsets.only(right: 10),
  304. child: ClipRRect(
  305. borderRadius: BorderRadius.circular(6.0),
  306. child: CachedNetworkImage(
  307. height: 45,
  308. width: 45,
  309. imageUrl:
  310. data['Headimgurl'] == null ? "" : data['Headimgurl'],
  311. placeholder: CustomUI.buildImgLoding,
  312. fit: BoxFit.cover,
  313. ),
  314. ),
  315. ),
  316. Positioned(
  317. right: 5,
  318. bottom: 0,
  319. child: Container(
  320. padding: EdgeInsets.only(bottom: 1.3, left: 0.5),
  321. decoration: BoxDecoration(
  322. color: Colors.white,
  323. borderRadius: BorderRadius.all(Radius.circular(20))),
  324. child: Icon(
  325. IconData(
  326. !isMan ? 0xe639 : 0xe638,
  327. fontFamily: 'iconfont',
  328. ),
  329. color: !isMan
  330. ? const Color(0xff0072ff)
  331. : const Color(0xffff0486),
  332. size: 12,
  333. ),
  334. ))
  335. ],
  336. )),
  337. Expanded(
  338. child: Column(
  339. crossAxisAlignment: CrossAxisAlignment.start,
  340. children: <Widget>[
  341. Container(
  342. child: RichText(
  343. text: TextSpan(children: [
  344. TextSpan(
  345. text: Provider.of<RefNameProvider>(context)
  346. .getRefName(data['UserId'], data['NickName']),
  347. style:
  348. TextStyle(fontSize: 14, color: Constants.BlackTextColor)),
  349. TextSpan(
  350. text: I18n.of(context).signed_up.replaceFirst('/s1', ''),
  351. style:
  352. TextStyle(fontSize: 13, color: Constants.GreyTextColor)),
  353. ])),
  354. ),
  355. Text(
  356. '${data['CreateTime']}',
  357. textScaleFactor: 1.0,
  358. style: TextStyle(color: Constants.LightGreyTextColor, fontSize: 12),
  359. ),
  360. ],
  361. )),
  362. InkWell(
  363. onTap: () {
  364. Navigator.of(context).push(
  365. new MaterialPageRoute(
  366. builder: (context) {
  367. return InformUserPage(
  368. isMan: !isMan,
  369. userId: data['UserId'],
  370. );
  371. },
  372. ),
  373. );
  374. },
  375. child: Container(
  376. padding: EdgeInsets.only(left: 10, right: 10, bottom: 10),
  377. alignment: Alignment.topRight,
  378. child: Text(
  379. I18n.of(context).report,
  380. textScaleFactor: 1.0,
  381. style: TextStyle(color: Constants.BlackTextColor),
  382. )))
  383. ]);
  384. Widget img = Container(
  385. child: Row(
  386. children: <Widget>[
  387. InkWell(
  388. onTap: () {
  389. Navigator.of(context).push(
  390. new MaterialPageRoute(
  391. builder: (context) {
  392. return PicSwiper(
  393. id: 0, pics: [PicSwiperItem(data['ImgUrl'], id: 0)]);
  394. },
  395. ),
  396. );
  397. },
  398. child: Container(
  399. margin: EdgeInsets.only(top: 10, left: 60),
  400. height: 80,
  401. width: 100,
  402. decoration:
  403. BoxDecoration(borderRadius: BorderRadius.circular(2.0)),
  404. child: ClipRRect(
  405. borderRadius: BorderRadius.circular(8),
  406. child: CachedNetworkImage(
  407. imageUrl: data['ImgUrl'] == null ? "" : data['ImgUrl'],
  408. placeholder: CustomUI.buildImgLoding,
  409. fit: BoxFit.cover,
  410. ),
  411. ))),
  412. Expanded(
  413. child: Container(
  414. height: 90,
  415. alignment: Alignment.bottomRight,
  416. child: InkWell(
  417. child: Container(
  418. margin: EdgeInsets.only(right: 10),
  419. decoration: BoxDecoration(
  420. color: const Color(0xFF547CFF),
  421. borderRadius: BorderRadius.all(Radius.circular(5))),
  422. padding:
  423. EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5),
  424. child: Text(
  425. !isMan
  426. ? I18n.of(context).talk_him
  427. : I18n.of(context).contact_her,
  428. textScaleFactor: 1.0,
  429. style: TextStyle(color: Colors.white, fontSize: 13),
  430. ),
  431. ),
  432. onTap: () {
  433. int fdId = data['UserId'];
  434. int sessionId = UserData().getSessionId(fdId);
  435. MsgHandler.updateActiveSesstion(sessionId);
  436. AppNavigator.pushChatPage(context, fdId);
  437. },
  438. ),
  439. ),
  440. )
  441. ],
  442. ),
  443. );
  444. return Container(
  445. padding: EdgeInsets.only(top: 10, bottom: 10),
  446. decoration: BoxDecoration(
  447. color: Colors.grey[100],
  448. borderRadius: BorderRadius.all(Radius.circular(10))),
  449. margin: EdgeInsets.only(top: 10),
  450. width: MediaQuery.of(context).size.width * 0.95,
  451. child: Column(
  452. children: <Widget>[basicInfo, img],
  453. ));
  454. }
  455. Widget _buildJoinList() {
  456. if (enrollList == null || enrollList.length == 0) {
  457. return Container();
  458. }
  459. return isMyself
  460. ? Container(
  461. child: Column(
  462. children: enrollList.map((data) {
  463. return _buildJoinItem(data);
  464. }).toList(),
  465. ),
  466. )
  467. : Container();
  468. }
  469. Widget _buildContent() {
  470. if (evaluateList == null || evaluateList.length == 0) {
  471. return Container();
  472. }
  473. const maxNum = 2;
  474. Widget button = InkWell(
  475. highlightColor: Colors.transparent,
  476. radius: 0,
  477. onTap: () {
  478. setState(() {
  479. showAllContent = !showAllContent;
  480. });
  481. },
  482. child: Padding(
  483. padding: EdgeInsets.only(top: 5, bottom: 5),
  484. child: Row(
  485. children: <Widget>[
  486. Text(
  487. !showAllContent
  488. ? I18n.of(context).expand
  489. : I18n.of(context).collapse,
  490. textScaleFactor: 1.0,
  491. style: TextStyle(fontSize: 12, color: Colors.grey),
  492. ),
  493. Icon(
  494. !showAllContent
  495. ? Icons.keyboard_arrow_down
  496. : Icons.keyboard_arrow_up,
  497. size: 18,
  498. color: Colors.grey,
  499. )
  500. ],
  501. ),
  502. ),
  503. );
  504. List<Widget> list = [];
  505. int showNum = evaluateList.length;
  506. if (evaluateList.length >= maxNum && !showAllContent) {
  507. showNum = maxNum;
  508. }
  509. for (int i = 0; i < showNum; i++) {
  510. var data = evaluateList[i];
  511. list.add(_buildReply(data));
  512. }
  513. if (evaluateList.length > maxNum) {
  514. list.add(button);
  515. }
  516. return Container(
  517. margin: EdgeInsets.only(left: 23, top: 10, right: 8, bottom: 10),
  518. child: Column(
  519. crossAxisAlignment: CrossAxisAlignment.start,
  520. children: list,
  521. ));
  522. }
  523. Widget _buildBody() {
  524. return new ListView(
  525. children: isLoadingFish
  526. ? <Widget>[
  527. MessageBox(isDetail: true, programInfo: programInfo),
  528. // _buildBigImg(programInfo),
  529. // _buildImgList(),
  530. _buildContent(),
  531. _buildJoinList(),
  532. ]
  533. : [],
  534. );
  535. }
  536. @override
  537. void dispose() {
  538. registKey = null;
  539. MessageMgr().off('update_dy', msgUpdateDy);
  540. MessageMgr().off('delete_program', msgDeleteProgram);
  541. MessageMgr().off('refresh_list', msgRefreshList);
  542. super.dispose();
  543. }
  544. }