YSSquareArticle.dart 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. import 'dart:io';
  2. import 'dart:math';
  3. import 'dart:ui';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/cupertino.dart';
  6. import 'package:flutter_easyrefresh/easy_refresh.dart';
  7. import 'package:image_picker/image_picker.dart';
  8. import 'package:qiniu_flutter_sdk/qiniu_flutter_sdk.dart';
  9. import 'package:ysairplane2/tools/YSNetWorking.dart';
  10. import 'package:ysairplane2/tools/YSTools.dart';
  11. const APPBAR_SCROLL_OFFSET = 100; //设置滑动变化的偏移量
  12. class YSSquareArticle extends StatefulWidget {
  13. final squareId,typeId,isShow;
  14. const YSSquareArticle({Key key, this.squareId, this.typeId, this.isShow}) : super(key: key);
  15. @override
  16. _YSSquareArticleState createState() => _YSSquareArticleState();
  17. }
  18. class _YSSquareArticleState extends State<YSSquareArticle> {
  19. ScrollController _scroll = ScrollController();
  20. double appBarAlpha = 0;
  21. double start = 0;
  22. double number = 0;
  23. int _page = 1;
  24. List _dataArray = [];
  25. List _imageArray = [];
  26. String _tokenStr = '';
  27. String _urlStr = '';
  28. TextEditingController _textField = TextEditingController();
  29. var _imageSet;
  30. _onScroll(offset) {
  31. double alpha = offset / APPBAR_SCROLL_OFFSET;
  32. if (alpha < 0) {
  33. alpha = 0;
  34. } else if (alpha > 1) {
  35. alpha = 1;
  36. }
  37. setState(() {
  38. appBarAlpha = alpha;
  39. });
  40. }
  41. Map _dict;
  42. @override
  43. void initState() {
  44. Future.delayed(Duration(seconds: 0)).then((value){
  45. _getSquareDetailData();
  46. _getQiNiuTokenData();
  47. });
  48. super.initState();
  49. }
  50. @override
  51. void dispose() {
  52. _textField.dispose();
  53. super.dispose();
  54. }
  55. @override
  56. Widget build(BuildContext context) {
  57. return Scaffold(
  58. body: SingleChildScrollView(
  59. child: _dict==null?Container(
  60. height: MediaQuery.of(context).padding.top+44,
  61. padding: EdgeInsets.only(left: 15,right: 15,top: MediaQuery.of(context).padding.top),
  62. color: Colors.white,
  63. child: Row(
  64. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  65. children: [
  66. GestureDetector(
  67. onTap: (){
  68. Navigator.pop(context);
  69. },
  70. child: Icon(Icons.arrow_back_ios,size: 20,color: Color(0xFF000000),),
  71. ),
  72. Text('详情',style: TextStyle(fontSize: 18,color: Color(0xFF000000),decoration: TextDecoration.none),),
  73. Icon(Icons.share,size: 25,color: Color(0xFF000000),)
  74. ],
  75. ),
  76. ):Column(
  77. children: [
  78. Stack(
  79. children: [
  80. Container(
  81. height: MediaQuery.of(context).size.height-(widget.isShow?50:0),
  82. child: Listener(
  83. onPointerDown: (PointerDownEvent pointerDownEvent) {
  84. start = pointerDownEvent.position.dy;
  85. },
  86. onPointerMove: (PointerMoveEvent pointerMoveEvent) {
  87. setState(() {
  88. number = (pointerMoveEvent.position.dy-start)/5;
  89. });
  90. },
  91. onPointerUp: (PointerUpEvent upEvent) {
  92. setState(() {
  93. number = 0;
  94. });
  95. },
  96. child: NotificationListener(
  97. onNotification: (scrollNotification) {
  98. if (scrollNotification is ScrollUpdateNotification &&
  99. scrollNotification.depth == 0) {
  100. //滚动且是列表滚动的时候
  101. _onScroll(scrollNotification.metrics.pixels);
  102. return true;
  103. }else{
  104. return false;
  105. }
  106. },
  107. child: EasyRefresh(
  108. onRefresh: _getSquareDetailData,
  109. onLoad: _loadMore,
  110. header: MaterialHeader(
  111. ),
  112. footer: BezierBounceFooter(
  113. backgroundColor: Colors.transparent,
  114. color: Colors.transparent,
  115. ),
  116. child: SingleChildScrollView(
  117. controller: _scroll,
  118. padding: EdgeInsets.all(0),
  119. child: Stack(
  120. children: [
  121. Container(
  122. height: 240+number,
  123. width: MediaQuery.of(context).size.width,
  124. child: Image(
  125. image: NetworkImage('${_dict['topicCover']}'),
  126. fit: BoxFit.fill,
  127. ),
  128. ),
  129. Container(
  130. margin: EdgeInsets.only(top: 230+number),
  131. decoration: BoxDecoration(
  132. color: Colors.white,
  133. borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10))
  134. ),
  135. child: Column(
  136. children: [
  137. Container(
  138. height: 60,
  139. padding: EdgeInsets.only(left: 15,right: 15,top: 10,bottom: 10),
  140. child: Row(
  141. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  142. children: [
  143. Container(
  144. height: 40,
  145. width: 40,
  146. decoration: BoxDecoration(
  147. borderRadius: BorderRadius.all(Radius.circular(20)),
  148. image: DecorationImage(image: NetworkImage('${_dict['user']['avatar']}'),fit: BoxFit.fill)
  149. ),
  150. margin: EdgeInsets.only(right: 6),
  151. ),
  152. Column(
  153. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  154. children: [
  155. Container(
  156. width: MediaQuery.of(context).size.width-170,
  157. child: Text('${_dict['user']['nickname']}',style: TextStyle(fontSize: 14,color: Color(0xFF333333),decoration: TextDecoration.none),),
  158. ),
  159. Container(
  160. width: MediaQuery.of(context).size.width-170,
  161. child: Text('旅游达人',style: TextStyle(fontSize: 10,color: Color(0xFF999999),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  162. )
  163. ],
  164. ),
  165. StatefulBuilder(
  166. builder: (context,followSet){
  167. return GestureDetector(
  168. onTap: () async{
  169. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/attention',
  170. parameter: {'userId':_dict['userId']},isLoading: false,isToken: true);
  171. if(dict!=null){
  172. followSet(() {
  173. _dict['followStatus'] = dict['data'];
  174. });
  175. }
  176. },
  177. child: _dict['followStatus']==1?Container(
  178. height: 30,
  179. width: 65,
  180. decoration: BoxDecoration(
  181. color: Colors.grey.withOpacity(0.3),
  182. borderRadius: BorderRadius.all(Radius.circular(50))
  183. ),
  184. alignment: Alignment.center,
  185. child: Text('已关注',style: TextStyle(fontSize: zsp(28),color:
  186. Colors.grey,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  187. ):Container(
  188. height: 30,
  189. width: 65,
  190. child: Image.asset('lib/images/look.png'),
  191. ),
  192. );
  193. },
  194. ),
  195. ],
  196. ),
  197. ),
  198. Divider(
  199. height: 0.5,
  200. color: Color(0xFFE5E5E5),
  201. ),
  202. Container(
  203. width: MediaQuery.of(context).size.width,
  204. padding: EdgeInsets.only(top: 15,left: 10,right: 10,bottom: 15),
  205. child: Text('${_dict['topicTitle']}',style: TextStyle(fontSize: 17,color: Color(0xFF333333),decoration: TextDecoration.none),),
  206. ),
  207. Container(
  208. width: MediaQuery.of(context).size.width,
  209. padding: EdgeInsets.only(left: 10,right: 10,bottom: 15),
  210. child: Text('${_dict['topicContent']}',
  211. style: TextStyle(fontSize: 14,color: Color(0xFF666666),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  212. ),
  213. if(widget.isShow)Container(
  214. height: 10,
  215. color: Color(0xFFF1F2F4),
  216. margin: EdgeInsets.only(bottom: 10),
  217. ),
  218. if(widget.isShow)Container(
  219. width: MediaQuery.of(context).size.width,
  220. padding: EdgeInsets.only(left: 10,right: 10,bottom: 15),
  221. child: Text('${_dataArray.length}条评论',style: TextStyle(fontSize: 13,color: Color(0xFF666666),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  222. ),
  223. if(widget.isShow)Container(
  224. height: 50,
  225. padding: EdgeInsets.only(left: 10,right: 10,bottom: 10),
  226. child: Row(
  227. children: [
  228. Container(
  229. height: 40,
  230. width: 40,
  231. decoration: BoxDecoration(
  232. borderRadius: BorderRadius.all(Radius.circular(20)),
  233. color: Color(0xFF151515)
  234. ),
  235. ),
  236. GestureDetector(
  237. onTap: (){
  238. _showInputView();
  239. },
  240. child: Container(
  241. height: 40,
  242. margin: EdgeInsets.only(left: 10),
  243. padding: EdgeInsets.only(left: 10,right: 10),
  244. width: MediaQuery.of(context).size.width-80,
  245. decoration: BoxDecoration(
  246. borderRadius: BorderRadius.all(Radius.circular(20)),
  247. color: Color(0xFFF5F5F5)
  248. ),
  249. alignment: Alignment.centerLeft,
  250. child: Text('有爱评论,说点儿好听的~',style: TextStyle(fontSize: 14,color: Color(0xFF595959),decoration: TextDecoration.none,fontWeight: FontWeight.normal),)
  251. ),
  252. ),
  253. ],
  254. ),
  255. ),
  256. Container(
  257. child: ListView.separated(
  258. padding: EdgeInsets.only(top: 15),
  259. shrinkWrap: true,
  260. itemBuilder: (context,index){
  261. return Container(
  262. child: Column(
  263. children: [
  264. Container(
  265. padding: EdgeInsets.only(left: 10,right: 10,bottom: 10),
  266. child: Row(
  267. crossAxisAlignment: CrossAxisAlignment.start,
  268. children: [
  269. Container(
  270. height: 40,
  271. width: 40,
  272. decoration: BoxDecoration(
  273. borderRadius: BorderRadius.all(Radius.circular(20)),
  274. image: DecorationImage(image: NetworkImage('${_dataArray[index]['avatar']}'),fit: BoxFit.fill)
  275. ),
  276. ),
  277. Container(
  278. margin: EdgeInsets.only(left: 10),
  279. width: MediaQuery.of(context).size.width-70,
  280. child: Column(
  281. crossAxisAlignment: CrossAxisAlignment.start,
  282. children: [
  283. GestureDetector(
  284. child: Text('${_dataArray[index]['nickname']}',
  285. style: TextStyle(fontSize: 14,color: Color(0xFF3C61B1),decoration: TextDecoration.none,fontWeight: FontWeight.bold),),
  286. onTap: (){
  287. _showInputView(type: 1,toUserid: int.parse('${_dataArray[index]['fromUserId']}'),
  288. fatherCommentId: int.parse('${_dataArray[index]['id']}'),fromUserId: int.parse('${_dataArray[index]['fromUserId']}'));
  289. },
  290. ),
  291. Text('${_dataArray[index]['comment']}',style: TextStyle(fontSize: 15,color: Color(0xFF333333),decoration: TextDecoration.none,fontWeight: FontWeight.normal)),
  292. ],
  293. ),
  294. )
  295. ],
  296. ),
  297. ),
  298. Container(
  299. child: ListView.separated(
  300. itemBuilder: (context,indexSub){
  301. return Row(
  302. crossAxisAlignment: CrossAxisAlignment.start,
  303. children: [
  304. Container(
  305. height: 20,
  306. width: 20,
  307. decoration: BoxDecoration(
  308. borderRadius: BorderRadius.all(Radius.circular(20)),
  309. image: DecorationImage(image: NetworkImage('${_dataArray[index]['dtSquareCommentsList'][indexSub]['avatar']}'),fit: BoxFit.fill)
  310. ),
  311. ),
  312. Container(
  313. margin: EdgeInsets.only(left: 10),
  314. width: MediaQuery.of(context).size.width-130,
  315. child: Column(
  316. crossAxisAlignment: CrossAxisAlignment.start,
  317. children: [
  318. GestureDetector(
  319. child: Text('${_dataArray[index]['dtSquareCommentsList'][indexSub]['nickname']}',
  320. style: TextStyle(fontSize: 14,color: Color(0xFF3C61B1),decoration: TextDecoration.none,fontWeight: FontWeight.bold),),
  321. onTap: (){
  322. _showInputView(type: 1,toUserid: _dataArray[index]['dtSquareCommentsList'][indexSub]['fromUserId'],
  323. fatherCommentId: _dataArray[index]['dtSquareCommentsList'][indexSub]['fatherCommentId']);
  324. },
  325. ),
  326. RichText(
  327. text: TextSpan(
  328. style: TextStyle(fontSize: 14,color: Color(0xFF333333),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  329. text: '回复',
  330. children: [
  331. TextSpan(
  332. text: ' ${_dataArray[index]['dtSquareCommentsList'][indexSub]['otherNickname']}:',
  333. style: TextStyle(color: Color(0xFF3C61B1),fontWeight: FontWeight.bold)
  334. ),
  335. TextSpan(
  336. text: '${_dataArray[index]['dtSquareCommentsList'][indexSub]['comment']}',
  337. style: TextStyle(color: Color(0xFF333333))
  338. ),
  339. TextSpan(
  340. text: ' ${_dataArray[index]['dtSquareCommentsList'][indexSub]['timeNode']}',
  341. style: TextStyle(color: Color(0xFF999999),fontSize: 12)
  342. )
  343. ]
  344. ),
  345. )
  346. ],
  347. ),
  348. )
  349. ],
  350. );
  351. },
  352. separatorBuilder: (context,index){
  353. return Container(
  354. height: 5,
  355. );
  356. },
  357. itemCount: (_dataArray[index]['dtSquareCommentsList']).length,
  358. shrinkWrap: true,
  359. padding: EdgeInsets.only(left: 60,right: 40),
  360. physics: NeverScrollableScrollPhysics(),
  361. ),
  362. )
  363. ],
  364. ),
  365. );
  366. },
  367. separatorBuilder: (context,index){
  368. return Container(
  369. height: 5,
  370. );
  371. },
  372. itemCount: _dataArray.length,
  373. physics: NeverScrollableScrollPhysics(),
  374. ),
  375. )
  376. ],
  377. ),
  378. ),
  379. ],
  380. ),
  381. ),
  382. ),
  383. ),
  384. ),
  385. ),
  386. Container(
  387. height: MediaQuery.of(context).padding.top+44,
  388. padding: EdgeInsets.only(left: 15,right: 15,top: MediaQuery.of(context).padding.top),
  389. color: Colors.white.withOpacity(appBarAlpha),
  390. child: Row(
  391. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  392. children: [
  393. GestureDetector(
  394. onTap: (){
  395. Navigator.pop(context);
  396. },
  397. child: Icon(Icons.arrow_back_ios,size: 20,color: appBarAlpha>0.5?Color(0xFF000000):Colors.white,),
  398. ),
  399. if(appBarAlpha>0.5)Text('详情',style: TextStyle(fontSize: 18,color: Color(0xFF000000),decoration: TextDecoration.none),),
  400. PopupMenuButton<String>(
  401. itemBuilder: (context) {
  402. return <PopupMenuEntry<String>>[
  403. PopupMenuItem<String>(
  404. value: '不感兴趣',
  405. child: Text('不感兴趣'),
  406. ),
  407. PopupMenuItem<String>(
  408. value: '拉黑',
  409. child: Text('拉黑'),
  410. ),
  411. PopupMenuItem<String>(
  412. value: '举报',
  413. child: Text('举报'),
  414. ),
  415. ];
  416. },
  417. icon: Icon(Icons.more_horiz_outlined,size: 25,color: appBarAlpha>0.5?Color(0xFF000000):Colors.white,),
  418. padding: EdgeInsets.all(0),
  419. onSelected: (value) async{
  420. if(value=='举报'){
  421. _imageArray.clear();
  422. _textField.text = '';
  423. showModalBottomSheet(
  424. context: context,
  425. builder: (context){
  426. return Container(
  427. height: hsp(700),
  428. width: MediaQuery.of(context).size.width,
  429. color: Colors.white,
  430. child: Column(
  431. children: [
  432. Container(
  433. height: hsp(100),
  434. child: Text('举报',style: TextStyle(fontSize: zsp(30),color: Colors.black),),
  435. alignment: Alignment.center,
  436. decoration: BoxDecoration(
  437. border: Border(bottom: BorderSide(color: Color(0xFFEEEEEE),width: 0.5))
  438. ),
  439. ),
  440. Container(
  441. height: hsp(300),
  442. child: CupertinoTextField(
  443. placeholder: '请输入举报理由',
  444. style: TextStyle(fontSize: zsp(30),color: Color(0xFF333739)),
  445. maxLines: 50,
  446. controller: _textField,
  447. ),
  448. padding: EdgeInsets.all(hsp(30)),
  449. ),
  450. StatefulBuilder(
  451. builder: (context,imageSet){
  452. _imageSet = imageSet;
  453. return Container(
  454. height: hsp(200),
  455. child: GridView.builder(
  456. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  457. crossAxisCount: 1,
  458. mainAxisSpacing: hsp(30)
  459. ),
  460. scrollDirection: Axis.horizontal,
  461. itemBuilder: (context,index){
  462. return _imageArray.length>index?Container(
  463. child: Image.network(_imageArray[index],fit: BoxFit.fill,),
  464. ):GestureDetector(
  465. onTap: () async{
  466. ImagePicker _picker = ImagePicker();
  467. showCupertinoModalPopup(
  468. context: context,
  469. builder: (context) {
  470. return CupertinoActionSheet(
  471. actions: <Widget>[
  472. CupertinoActionSheetAction(
  473. child: Text('拍摄照片'),
  474. onPressed: () {
  475. Navigator.pop(context);
  476. _picker.getImage(source: ImageSource.camera).then((value){
  477. _onUpload(value);
  478. });
  479. },
  480. ),
  481. CupertinoActionSheetAction(
  482. child: Text('选择图片'),
  483. onPressed: () {
  484. Navigator.pop(context);
  485. _picker.getImage(source: ImageSource.gallery).then((value){
  486. _onUpload(value);
  487. });
  488. },
  489. ),
  490. ],
  491. cancelButton: CupertinoActionSheetAction(
  492. child: Text('取消'),
  493. onPressed: () {
  494. Navigator.pop(context);
  495. },
  496. ),
  497. );
  498. }
  499. );
  500. },
  501. child: Container(
  502. decoration: BoxDecoration(
  503. border: Border.all(color: Color(0xFFEEEEEE),width: 1)
  504. ),
  505. child: Icon(Icons.add_photo_alternate_rounded,color: Color(0xFFEEEEEE),size: hsp(80),),
  506. alignment: Alignment.center,
  507. ),
  508. );
  509. },
  510. itemCount: _imageArray.length>0?_imageArray.length:_imageArray.length+1,
  511. ),
  512. padding: EdgeInsets.only(left: hsp(30),right: hsp(30),bottom: hsp(30)),
  513. );
  514. },
  515. ),
  516. GestureDetector(
  517. child: Container(
  518. height: hsp(100),
  519. color: Color(0xFF007AFF),
  520. margin: EdgeInsets.only(left: hsp(50),right: hsp(50)),
  521. child: Text('提交',style: TextStyle(fontSize: zsp(30),color: Colors.white),),
  522. alignment: Alignment.center,
  523. ),
  524. onTap: () async{
  525. if(_textField.text.isEmpty){
  526. ysFlutterToast(context, '请输入举报理由');
  527. return;
  528. }
  529. if(_imageArray.length==0){
  530. ysFlutterToast(context, '请添加举报图片');
  531. return;
  532. }
  533. String url = '/app/applets/feedback/toReport';
  534. Map request = {};
  535. request['type'] = 1;
  536. request['did'] = widget.squareId;
  537. request['content'] = _textField.text;
  538. request['pic'] = _imageArray[0];
  539. Map dict = await ysRequestHttp(context, type: requestType.post,api: url,parameter: request,isLoading: false,isToken: true);
  540. if (dict != null) {
  541. ysFlutterToast(context,'已举报该用户');
  542. Navigator.of(context).pop('');
  543. }
  544. },
  545. ),
  546. ],
  547. ),
  548. );
  549. }
  550. );
  551. }else{
  552. String url = '/app/black/shielding';
  553. Map request = {};
  554. request['type'] = 1;
  555. request['did'] = widget.squareId;
  556. if(value=='拉黑'){
  557. request['isBlack'] = 1;
  558. }else if(value=='不感兴趣'){
  559. request['isBlack'] = 0;
  560. }
  561. Map dict = await ysRequestHttp(context, type: requestType.post,api: url,parameter: request,isLoading: false,isToken: true);
  562. if (dict != null) {
  563. ysFlutterToast(context,'${value=='不感兴趣'?'此内容已添加为不感兴趣':'已拉黑该用户'}');
  564. Navigator.of(context).pop('');
  565. }
  566. }
  567. },
  568. )
  569. ],
  570. ),
  571. )
  572. ],
  573. ),
  574. if(widget.isShow)Container(
  575. height: 50,
  576. padding: EdgeInsets.only(left: 15,right: 15),
  577. color: Color(0xFFF5F5F5),
  578. child: Row(
  579. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  580. children: [
  581. Container(
  582. width: MediaQuery.of(context).size.width-120,
  583. padding: EdgeInsets.only(left: 15,right: 15),
  584. height: 30,
  585. decoration: BoxDecoration(
  586. color: Colors.white,
  587. borderRadius: BorderRadius.all(Radius.circular(15))
  588. ),
  589. child: Row(
  590. children: [
  591. GestureDetector(
  592. onTap: (){
  593. _showInputView(type: 0);
  594. },
  595. child: Container(
  596. width: MediaQuery.of(context).size.width-175,
  597. child: Text('我来说两句',style: TextStyle(fontSize: 14,color: Color(0xFF999999),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  598. ),
  599. ),
  600. Icon(Icons.tag_faces,size: 25,color: Color(0xFFF5F5F5),),
  601. ],
  602. ),
  603. ),
  604. GestureDetector(
  605. onTap: (){
  606. _postAgreementData(1);
  607. },
  608. child: Container(
  609. height: 20,
  610. width: 20,
  611. child: Image.asset(_dict==null?'lib/images/love.png':_dict['likeStatus']==1?'lib/images/love2.png':'lib/images/love.png'),
  612. ),
  613. ),
  614. GestureDetector(
  615. child: Icon(_dict==null?Icons.star_border:_dict['collectStatus']==1?Icons.star:Icons.star_border,size: 20,color: Color(0xFFF5C419),),
  616. onTap: (){
  617. _postAgreementData(0);
  618. },
  619. ),
  620. // Icon(Icons.share,size: 20,color: Color(0xFF404040),),
  621. ],
  622. ),
  623. ),
  624. ],
  625. ),
  626. ),
  627. );
  628. }
  629. _showInputView({int type,int toUserid,int fatherCommentId,int fromUserId}){
  630. TextEditingController _text = TextEditingController();
  631. showModalBottomSheet(
  632. context: context,
  633. barrierColor: Colors.transparent,
  634. backgroundColor: Colors.transparent,
  635. isScrollControlled: true,
  636. builder: (context){
  637. return SingleChildScrollView(
  638. padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
  639. child: Container(
  640. height: 140,
  641. padding: EdgeInsets.only(left: hsp(30),right: hsp(30),top: hsp(30)),
  642. decoration: BoxDecoration(
  643. borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)),
  644. color: Colors.white,
  645. boxShadow: [
  646. BoxShadow(
  647. color: Colors.black26,
  648. blurRadius: 10
  649. )
  650. ]
  651. ),
  652. child: Column(
  653. children: [
  654. Row(
  655. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  656. children: [
  657. Text('评论',style: TextStyle(fontSize: 15,color: Color(0xFF424242),decoration: TextDecoration.none,fontWeight: FontWeight.bold),),
  658. GestureDetector(
  659. child: Text('发布',style: TextStyle(fontSize: 15,color: Color(0xFF4187D9),decoration: TextDecoration.none,fontWeight: FontWeight.bold),),
  660. onTap: (){
  661. Navigator.pop(context);
  662. if(type==0){
  663. _postCommentData({'comment':_text.text,'topicId':widget.squareId,'fatherCommentId':0,'fromUserId':0});
  664. }else{
  665. _postCommentData({'comment':_text.text,'topicId':widget.squareId,'fatherCommentId':fatherCommentId,'toUserId':toUserid,'fromUserId':fromUserId});
  666. }
  667. },
  668. ),
  669. ],
  670. ),
  671. Container(
  672. height: 50,
  673. decoration: BoxDecoration(
  674. color: Color(0xFFF7F7F7),
  675. borderRadius: BorderRadius.all(Radius.circular(10))
  676. ),
  677. margin: EdgeInsets.only(top: 10,bottom: 10),
  678. child: CupertinoTextField(
  679. placeholder: '友善发言,理性讨论,阳光你我',
  680. style: TextStyle(fontSize: 14,color: Color(0xFF999999),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  681. placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFF999999),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  682. decoration: BoxDecoration(),
  683. maxLines: 50,
  684. autofocus: true,
  685. controller: _text,
  686. ),
  687. ),
  688. Row(
  689. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  690. children: [
  691. Container(),
  692. Icon(Icons.tag_faces,size: 25,color: Color(0xFF5C5C5C),),
  693. ],
  694. )
  695. ],
  696. ),
  697. ),
  698. );
  699. }
  700. );
  701. }
  702. _postCommentData(Map parma) async{
  703. Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/piazza/SquareCommunity/comment/add',
  704. parameter: parma,isLoading: false,isToken: true);
  705. if(dict!=null){
  706. FocusScope.of(context).requestFocus(FocusNode());
  707. _refreshData();
  708. }
  709. }
  710. Future<void> _getSquareDetailData() async{
  711. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/details'
  712. ,parameter: {'id':widget.squareId,'type':widget.typeId},isLoading: true,isToken: true,refresh: (){
  713. _getSquareDetailData();
  714. });
  715. if(dict!=null){
  716. setState(() {
  717. _dict = dict['data'];
  718. });
  719. _refreshData();
  720. }
  721. }
  722. Future<void> _refreshData() async{
  723. _page = 1;
  724. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/comment/list',
  725. parameter: {'pageNo':_page,'pageSize':10,'id':widget.squareId,'type':widget.typeId},isToken: true);
  726. if(dict!=null){
  727. setState(() {
  728. _dataArray = dict['data']['resultList'];
  729. _page = dict['data']['pageNum'];
  730. });
  731. }
  732. }
  733. Future<void> _loadMore() async{
  734. _page++;
  735. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/comment/list',
  736. parameter: {'pageNo':_page,'pageSize':10,'id':widget.squareId,'type':widget.typeId},isToken: true);
  737. if(dict!=null){
  738. setState(() {
  739. _dataArray.addAll(dict['data']['resultList']);
  740. _page = dict['data']['pageNum'];
  741. });
  742. }
  743. }
  744. _postAgreementData(int type) async{
  745. Map request = {'type':type};
  746. request['topicId'] = widget.squareId;
  747. Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/piazza/SquareCommunity/likeAndCollect',
  748. parameter: request,isLoading: false,isToken: true,refresh: (){
  749. });
  750. if(dict!=null){
  751. setState(() {
  752. if(type==1){
  753. _dict['likeStatus'] = dict['data'];
  754. }else{
  755. _dict['collectStatus'] = dict['data'];
  756. }
  757. });
  758. }
  759. }
  760. _onUpload(var value) async {
  761. if (value == null) {
  762. return;
  763. }
  764. print(value.path);
  765. print(_tokenStr);
  766. Storage storage = Storage();
  767. storage.putFile(
  768. File(value.path),
  769. _tokenStr,
  770. options: PutOptions(
  771. key: DateTime.now().millisecondsSinceEpoch.toString() +'.' +value.path.split('.').last,
  772. ),
  773. ).then((result) async{
  774. _imageSet(() {
  775. _imageArray.add(_urlStr+'${result.key}');
  776. });
  777. });
  778. }
  779. _getQiNiuTokenData() async{
  780. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/getToken',parameter: {},isLoading: false,isToken: false);
  781. if(dict!=null){
  782. _tokenStr = dict['token'];
  783. _urlStr = dict['prefix'];
  784. }
  785. }
  786. }