YSMineSquare.dart 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_easyrefresh/easy_refresh.dart';
  4. import 'package:ysairplane2/code/YSMessage.dart';
  5. import 'package:ysairplane2/tools/YSNetWorking.dart';
  6. import 'package:ysairplane2/tools/YSTools.dart';
  7. import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
  8. import 'YSSquareArticle.dart';
  9. import 'YSSquareVideo.dart';
  10. class YSMineSquare extends StatefulWidget {
  11. @override
  12. _YSMineSquareState createState() => _YSMineSquareState();
  13. }
  14. class _YSMineSquareState extends State<YSMineSquare> {
  15. ScrollController _scrollController = ScrollController();
  16. Map _dict;
  17. int _selected = 0;
  18. List _dataArray = [];
  19. int _page = 1;
  20. @override
  21. void initState() {
  22. Future.delayed(Duration(seconds: 0)).then((value){
  23. _getUserInfoData();
  24. });
  25. super.initState();
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. return CupertinoPageScaffold(
  30. child: EasyRefresh(
  31. onRefresh: _refresh,
  32. onLoad: _loadMore,
  33. header: MaterialHeader(
  34. ),
  35. footer: BezierBounceFooter(
  36. backgroundColor: Colors.transparent,
  37. color: Colors.transparent,
  38. ),
  39. child: SingleChildScrollView(
  40. child: Column(
  41. children: [
  42. Container(
  43. height: MediaQuery.of(context).padding.top+270,
  44. color: Colors.white,
  45. child: Stack(
  46. children: [
  47. Container(
  48. height: MediaQuery.of(context).padding.top+220,
  49. child: _dict==null?Image(
  50. image: AssetImage('lib/images/squareBg2.png'),
  51. ):ysImageLoad(
  52. imageUrl: '${_dict['backGroundUrl']}',
  53. fit: BoxFit.fill,
  54. height: MediaQuery.of(context).padding.top+270,
  55. width: MediaQuery.of(context).size.width
  56. ),
  57. ),
  58. Container(
  59. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+10,left: 15,right: 15),
  60. height: 50,
  61. child: Row(
  62. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  63. children: [
  64. GestureDetector(
  65. child: Icon(Icons.arrow_back_ios,size: 20,color: Colors.white,),
  66. onTap: (){
  67. Navigator.pop(context);
  68. },
  69. ),
  70. Stack(
  71. children: [
  72. GestureDetector(
  73. child: Image(image: AssetImage('lib/images/suqareMsg.png'),height: 20,width: 20,),
  74. onTap: (){
  75. Navigator.of(context).push(
  76. CupertinoPageRoute(
  77. builder: (context){
  78. return YSMessage();
  79. }
  80. )
  81. );
  82. },
  83. ),
  84. // Container(
  85. // margin: EdgeInsets.only(left: 15),
  86. // height: 15,
  87. // width: 15,
  88. // decoration: BoxDecoration(
  89. // color: Colors.red,
  90. // borderRadius: BorderRadius.all(Radius.circular(7.5))
  91. // ),
  92. // alignment: Alignment.center,
  93. // child: Text('6',style: TextStyle(fontSize: 11,color: Colors.white,fontWeight: FontWeight.normal,decoration: TextDecoration.none),),
  94. // )
  95. ],
  96. )
  97. ],
  98. ),
  99. ),
  100. Container(
  101. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+70,left: 15),
  102. height: MediaQuery.of(context).padding.top+170,
  103. width: MediaQuery.of(context).size.width-30,
  104. decoration: BoxDecoration(
  105. color: Colors.white,
  106. borderRadius: BorderRadius.all(Radius.circular(10)),
  107. boxShadow: [
  108. BoxShadow(
  109. color: Color(0xFFF4F4F4),
  110. blurRadius: 5,
  111. offset: Offset(0.5, 3.0),
  112. ),
  113. ]
  114. ),
  115. padding: EdgeInsets.all(15),
  116. child: Row(
  117. children: [
  118. Container(
  119. width: (MediaQuery.of(context).size.width-60)*0.6,
  120. padding: EdgeInsets.only(right: 30),
  121. child: Column(
  122. children: [
  123. Container(
  124. child: Row(
  125. children: [
  126. Text(_dict==null?'':(_dict['user']['nickname']).toString().length>8?(_dict['user']['nickname']).toString().substring(0,7)+'..':(_dict['user']['nickname']).toString(),
  127. style: TextStyle(fontSize: 16,color: Color(0xFF333333),fontWeight: FontWeight.bold,decoration: TextDecoration.none),maxLines: 1,overflow: TextOverflow.ellipsis,),
  128. Icon(Icons.pregnant_woman,color: Colors.pinkAccent,),
  129. ],
  130. ),
  131. ),
  132. Container(
  133. margin: EdgeInsets.only(top: 10,bottom: 10),
  134. child: Text(_dict==null?'':'${_dict['labelIds']}',
  135. style: TextStyle(fontSize: 12,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none),maxLines: 2,
  136. ),
  137. ),
  138. Container(
  139. margin: EdgeInsets.only(top: 10,bottom: 20),
  140. child: Row(
  141. children: [
  142. Container(
  143. child: Text('陕西西安',
  144. style: TextStyle(fontSize: 10,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  145. ),
  146. decoration: BoxDecoration(
  147. color: Color(0xFFEEEEEE),
  148. borderRadius: BorderRadius.all(Radius.circular(5))
  149. ),
  150. padding: EdgeInsets.all(5),
  151. ),
  152. Container(
  153. child: Text(_dict==null?'':'${_dict['user']['school']}',
  154. style: TextStyle(fontSize: 10,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  155. ),
  156. decoration: BoxDecoration(
  157. color: Color(0xFFEEEEEE),
  158. borderRadius: BorderRadius.all(Radius.circular(5))
  159. ),
  160. padding: EdgeInsets.all(5),
  161. margin: EdgeInsets.only(left: 5),
  162. ),
  163. ],
  164. ),
  165. ),
  166. Row(
  167. children: [
  168. Container(
  169. height: 32,
  170. width: 50,
  171. child: Column(
  172. children: [
  173. Text(_dict==null?'':'${_dict['attention']}',
  174. style: TextStyle(fontSize: 14,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  175. ),
  176. Text('关注',
  177. style: TextStyle(fontSize: 12,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  178. )
  179. ],
  180. ),
  181. ),
  182. Container(
  183. height: 32,
  184. width: 50,
  185. child: Column(
  186. children: [
  187. Text(_dict==null?'':'${_dict['fans']}',
  188. style: TextStyle(fontSize: 14,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  189. ),
  190. Text('粉丝',
  191. style: TextStyle(fontSize: 12,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  192. )
  193. ],
  194. ),
  195. ),
  196. Container(
  197. height: 32,
  198. width: 50,
  199. child: Column(
  200. children: [
  201. Text(_dict==null?'':'${_dict['likeCount']}',
  202. style: TextStyle(fontSize: 14,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  203. ),
  204. Text('喜欢',
  205. style: TextStyle(fontSize: 12,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  206. )
  207. ],
  208. ),
  209. )
  210. ],
  211. ),
  212. ],
  213. ),
  214. ),
  215. Container(
  216. width: (MediaQuery.of(context).size.width-60)*0.4,
  217. child: Column(
  218. mainAxisAlignment: MainAxisAlignment.center,
  219. children: [
  220. Container(
  221. height: 70,
  222. width: 70,
  223. decoration: BoxDecoration(
  224. image: DecorationImage(image: _dict==null?AssetImage('lib/images/head.png'):NetworkImage('${_dict['user']['avatar']}')),
  225. borderRadius: BorderRadius.all(Radius.circular(35))
  226. ),
  227. ),
  228. // GestureDetector(
  229. // onTap: (){
  230. // _showEditMsgView();
  231. // },
  232. // child: Container(
  233. // height: 26,
  234. // width: 60,
  235. // margin: EdgeInsets.only(top: 10),
  236. // padding: EdgeInsets.only(left: 8),
  237. // decoration: BoxDecoration(
  238. // color: Color(0xFFF4F4F4),
  239. // borderRadius: BorderRadius.all(Radius.circular(13)),
  240. // ),
  241. // child: Row(
  242. // children: [
  243. // Icon(Icons.edit,size: 15,color: Color(0xFF999999),),
  244. // Text('编辑',
  245. // style: TextStyle(fontSize: 12,color: Color(0xFF999999),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  246. // )
  247. // ],
  248. // ),
  249. // ),
  250. // )
  251. ],
  252. ),
  253. )
  254. ],
  255. ),
  256. )
  257. ],
  258. ),
  259. ),
  260. Container(
  261. width: MediaQuery.of(context).size.width,
  262. height: 50,
  263. color: Colors.white,
  264. padding: EdgeInsets.only(top: 20,left: 20,right: 20),
  265. child: ListView.separated(
  266. scrollDirection: Axis.horizontal,
  267. itemBuilder: (context,index){
  268. return GestureDetector(
  269. onTap: (){
  270. _selected = index;
  271. _refresh();
  272. },
  273. child: Container(
  274. height: 30,
  275. width: (MediaQuery.of(context).size.width-80)/3,
  276. child: Column(
  277. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  278. children: [
  279. Text(index==0?'作品':index==1?'关注':'收藏',style: TextStyle(fontSize: 16,color: index==_selected?Color(0xFF333333):Color(0xFF666666),decoration: TextDecoration.none,fontWeight: index==_selected?FontWeight.bold:FontWeight.normal),),
  280. Container(height: 2,width: 15,color: index==_selected?Color(0xFF333333):Colors.transparent,)
  281. ],
  282. ),
  283. ),
  284. );
  285. },
  286. separatorBuilder: (context,index){
  287. return Container(width: 20,);
  288. },
  289. itemCount: 3
  290. ),
  291. ),
  292. Container(
  293. margin: EdgeInsets.only(left: 10,right: 10),
  294. child: StaggeredGridView.countBuilder(
  295. shrinkWrap: true,
  296. controller: _scrollController,
  297. crossAxisCount: 4,
  298. crossAxisSpacing: 8,
  299. mainAxisSpacing: 8,
  300. itemCount: _dataArray.length,
  301. itemBuilder: (context, index) {
  302. return GestureDetector(
  303. onTap: (){
  304. Navigator.of(context,rootNavigator: true).push(
  305. CupertinoPageRoute(
  306. builder: (context){
  307. return _dataArray[index]['type']==1?YSSquareArticle(squareId: _dataArray[index]['id'],typeId: _dataArray[index]['type'],)
  308. :YSSquareVideo(squareId: _dataArray[index]['id'],typeId: _dataArray[index]['type'],);
  309. }
  310. )
  311. );
  312. },
  313. child: Stack(
  314. children: [
  315. Container(
  316. color: Colors.white,
  317. child:Column(
  318. children: [
  319. ysImageLoad(
  320. imageUrl: _dataArray[index]['type']==0?'${_dataArray[index]['coverPath']}':'${_dataArray[index]['topicCover']}',
  321. fit: BoxFit.fill,
  322. aspectRatio: double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}')
  323. ),
  324. Container(
  325. child: Text(_dataArray[index]['type']==0?'${_dataArray[index]['videoTitle']}':'${_dataArray[index]['topicTitle']}',
  326. style: TextStyle(fontSize: 13,color: Color(0xFF333333),decoration: TextDecoration.none,),maxLines: 2,overflow: TextOverflow.ellipsis,),
  327. padding: EdgeInsets.all(5),
  328. alignment: Alignment.centerLeft,
  329. ),
  330. Container(
  331. child: Row(
  332. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  333. children: [
  334. Row(
  335. children: [
  336. Container(
  337. height: 20,
  338. width: 20,
  339. margin: EdgeInsets.only(right: 5),
  340. decoration: BoxDecoration(
  341. color: Colors.black12,
  342. borderRadius: BorderRadius.all(Radius.circular(10)),
  343. ),
  344. child: ClipRRect(
  345. borderRadius: BorderRadius.all(Radius.circular(10)),
  346. child: ysImageLoad(
  347. imageUrl: '${_dataArray[index]['user']['avatar']}',
  348. fit: BoxFit.fill,
  349. height: 20,
  350. width: 20,
  351. ),
  352. ),
  353. ),
  354. Container(
  355. width: 70,
  356. child: Text('${_dataArray[index]['user']['nickname']}',
  357. style: TextStyle(fontSize: 12,color: Color(0xFF333333),decoration: TextDecoration.none,),overflow: TextOverflow.ellipsis,),
  358. )
  359. ],
  360. ),
  361. GestureDetector(
  362. behavior: HitTestBehavior.opaque,
  363. child: Row(
  364. children: [
  365. Container(
  366. height: 15,
  367. width: 15,
  368. margin: EdgeInsets.only(right: 5),
  369. child: Image.asset(_dataArray[index]['likeStatus']==0?'lib/images/love.png':'lib/images/love2.png')
  370. ),
  371. Container(
  372. child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Color(0xFFEE564C),decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,),
  373. )
  374. ],
  375. mainAxisSize: MainAxisSize.min,
  376. ),
  377. onTap: (){
  378. _postAgreementData(index);
  379. },
  380. ),
  381. ],
  382. ),
  383. padding: EdgeInsets.only(left: 5,right: 5,top: 3,bottom: 5),
  384. ),
  385. ],
  386. ),
  387. ),
  388. Container(
  389. height: 15,
  390. margin: EdgeInsets.only(top: 10,left: 10),
  391. decoration: BoxDecoration(
  392. color: Colors.black12,
  393. borderRadius: BorderRadius.all(Radius.circular(7.5)),
  394. ),
  395. child: Row(
  396. mainAxisSize: MainAxisSize.min,
  397. children: [
  398. Container(
  399. height: 10,
  400. width: 15,
  401. margin: EdgeInsets.only(right: 3),
  402. child: Image.asset('lib/images/eyes2.png')
  403. ),
  404. Container(
  405. child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Colors.white,decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,),
  406. )
  407. ],
  408. ),
  409. padding: EdgeInsets.only(left: 8,right: 8),
  410. ),
  411. _dataArray[index]['type']==0?Container(
  412. margin: EdgeInsets.only(left: (MediaQuery.of(context).size.width-25)/2-30,
  413. top: (MediaQuery.of(context).size.width-25)/2/(double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}'))-30),
  414. height: 20,
  415. width: 20,
  416. child: Icon(Icons.play_circle_filled,color: Colors.white,),
  417. ):Container()
  418. ],
  419. ),
  420. );
  421. },
  422. staggeredTileBuilder: (index) =>StaggeredTile.fit(2),
  423. padding: EdgeInsets.only(top: 10),
  424. ),
  425. )
  426. ],
  427. ),
  428. ),
  429. ),
  430. );
  431. }
  432. _showEditMsgView() async{
  433. showModalBottomSheet(
  434. backgroundColor: Colors.transparent,
  435. isScrollControlled: true,
  436. context: context,
  437. builder: (context){
  438. return Container(
  439. height: MediaQuery.of(context).size.height*0.8,
  440. width: MediaQuery.of(context).size.width,
  441. decoration: BoxDecoration(
  442. color: Colors.white,
  443. borderRadius: BorderRadius.all(Radius.circular(10))
  444. ),
  445. child: SingleChildScrollView(
  446. child: Column(
  447. children: [
  448. Container(
  449. height: hsp(112),
  450. padding: EdgeInsets.only(left: wsp(33),right: wsp(33)),
  451. child: Row(
  452. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  453. children: [
  454. GestureDetector(
  455. child: Text('取消',style: TextStyle(fontSize: zsp(34),color: Color(0xFF000000)),),
  456. onTap: (){
  457. Navigator.pop(context);
  458. },
  459. ),
  460. Text('保存',style: TextStyle(fontSize: zsp(34),color: Color(0xFF007AFF)),)
  461. ],
  462. ),
  463. ),
  464. Divider(color: Color(0xFFE5E5E5),height: hsp(1),thickness: hsp(1),),
  465. Container(
  466. child: ListView.separated(
  467. shrinkWrap: true,
  468. itemBuilder: (context,index){
  469. return Container(
  470. height: index==0?hsp(112):hsp(92),
  471. padding: EdgeInsets.only(left: wsp(33),right: wsp(33)),
  472. child: Row(
  473. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  474. children: [
  475. Text('标题',style: TextStyle(fontSize: zsp(32),color: Color(0xFF000000)),),
  476. index==0?Container(
  477. height: hsp(80),
  478. width: hsp(80),
  479. decoration: BoxDecoration(
  480. color: Colors.black12,
  481. borderRadius: BorderRadius.all(Radius.circular(hsp(40))),
  482. ),
  483. ):index==1||index==2?Text('UNI王一博',style: TextStyle(fontSize: zsp(32),color: Color(0xFF9A9A9A)),
  484. ):Row(
  485. children: [
  486. Text('陕西 西安',style: TextStyle(fontSize: zsp(32),color: Color(0xFF9A9A9A))),
  487. Icon(Icons.chevron_right,size: hsp(40),color: Color(0xFF9A9A9A))
  488. ],
  489. )
  490. ],
  491. ),
  492. );
  493. },
  494. separatorBuilder: (context,index){
  495. return Divider(color: Color(0xFFE5E5E5),height: hsp(1),thickness: hsp(1),);
  496. },
  497. itemCount: 5,
  498. physics: NeverScrollableScrollPhysics(),
  499. ),
  500. ),
  501. Divider(color: Color(0xFFE5E5E5),height: hsp(1),thickness: hsp(1),),
  502. Container(
  503. padding: EdgeInsets.all(hsp(33)),
  504. child: Column(
  505. crossAxisAlignment: CrossAxisAlignment.start,
  506. children: [
  507. Text('标题',style: TextStyle(fontSize: zsp(32),color: Color(0xFF000000)),),
  508. Container(height: hsp(10),),
  509. Text('歌手、演员、主持人男子演唱组合UNIQ成员,职业摩托车赛车手',style: TextStyle(fontSize: zsp(30),color: Color(0xFF9A9A9A)),),
  510. ],
  511. ),
  512. ),
  513. Divider(color: Color(0xFFE5E5E5),height: hsp(1),thickness: hsp(1),),
  514. ],
  515. ),
  516. ),
  517. );
  518. });
  519. }
  520. _getUserInfoData() async{
  521. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/community',parameter: {},isLoading: true,isToken: true);
  522. if(dict!=null){
  523. _refresh();
  524. setState(() {
  525. _dict = dict['data'];
  526. });
  527. }
  528. }
  529. Future<void> _refresh() async{
  530. _page = 1;
  531. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/look',
  532. parameter: {'pageNo':_page,'pageSize':10,'type':_selected},isLoading: false,isToken: true);
  533. if(dict!=null){
  534. setState(() {
  535. _dataArray = dict['data']['resultList'];
  536. });
  537. }
  538. }
  539. Future<void> _loadMore() async{
  540. _page++;
  541. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/look',
  542. parameter: {'pageNo':_page,'pageSize':10,'type':_selected},isLoading: false,isToken: true);
  543. if(dict!=null){
  544. setState(() {
  545. _dataArray.addAll(dict['data']['resultList']);
  546. });
  547. }
  548. }
  549. _postAgreementData(int index) async{
  550. Map request = {'type':1};
  551. if(_dataArray[index]['type']==0){
  552. request['squareId'] = _dataArray[index]['id'];
  553. }else{
  554. request['topicId'] = _dataArray[index]['id'];
  555. }
  556. Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/piazza/SquareCommunity/likeAndCollect',parameter: request,isLoading: false,isToken: true,refresh: (){
  557. });
  558. if(dict!=null){
  559. setState(() {
  560. _dataArray[index]['likeStatus'] = dict['data'];
  561. if(dict['data'] == 0){
  562. _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') - 1;
  563. }else{
  564. _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') + 1;
  565. }
  566. });
  567. }
  568. }
  569. }