YSMineSquare.dart 29 KB

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