YSMineSquare.dart 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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>7?(_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. setState(() {
  270. _selected = index;
  271. });
  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. AspectRatio(
  320. child: Container(
  321. decoration: BoxDecoration(
  322. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)),
  323. ),
  324. child: ClipRRect(
  325. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)),
  326. child: CachedNetworkImage(
  327. imageUrl: _dataArray[index]['type']==0?'${_dataArray[index]['coverPath']}':'${_dataArray[index]['topicCover']}',
  328. fit: BoxFit.fill
  329. ),
  330. ),
  331. ),
  332. aspectRatio: double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}')
  333. ),
  334. Container(
  335. child: Text(_dataArray[index]['type']==0?'${_dataArray[index]['videoTitle']}':'${_dataArray[index]['topicTitle']}',
  336. style: TextStyle(fontSize: 13,color: Color(0xFF333333),decoration: TextDecoration.none,),maxLines: 2,overflow: TextOverflow.ellipsis,),
  337. padding: EdgeInsets.all(5),
  338. alignment: Alignment.centerLeft,
  339. ),
  340. Container(
  341. child: Row(
  342. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  343. children: [
  344. Row(
  345. children: [
  346. Container(
  347. height: 20,
  348. width: 20,
  349. margin: EdgeInsets.only(right: 5),
  350. decoration: BoxDecoration(
  351. color: Colors.black12,
  352. borderRadius: BorderRadius.all(Radius.circular(10)),
  353. ),
  354. child: ClipRRect(
  355. borderRadius: BorderRadius.all(Radius.circular(10)),
  356. child: CachedNetworkImage(
  357. imageUrl: '${_dataArray[index]['user']['avatar']}',
  358. fit: BoxFit.fill,
  359. ),
  360. ),
  361. ),
  362. Container(
  363. width: 70,
  364. child: Text('${_dataArray[index]['user']['nickname']}',
  365. style: TextStyle(fontSize: 12,color: Color(0xFF333333),decoration: TextDecoration.none,),overflow: TextOverflow.ellipsis,),
  366. )
  367. ],
  368. ),
  369. GestureDetector(
  370. behavior: HitTestBehavior.opaque,
  371. child: Row(
  372. children: [
  373. Container(
  374. height: 15,
  375. width: 15,
  376. margin: EdgeInsets.only(right: 5),
  377. child: Image.asset(_dataArray[index]['likeStatus']==0?'lib/images/love.png':'lib/images/love2.png')
  378. ),
  379. Container(
  380. child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Color(0xFFEE564C),decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,),
  381. )
  382. ],
  383. mainAxisSize: MainAxisSize.min,
  384. ),
  385. onTap: (){
  386. _postAgreementData(index);
  387. },
  388. ),
  389. ],
  390. ),
  391. padding: EdgeInsets.only(left: 5,right: 5,top: 3,bottom: 5),
  392. ),
  393. ],
  394. ),
  395. ),
  396. Container(
  397. height: 15,
  398. margin: EdgeInsets.only(top: 10,left: 10),
  399. decoration: BoxDecoration(
  400. color: Colors.black12,
  401. borderRadius: BorderRadius.all(Radius.circular(7.5)),
  402. ),
  403. child: Row(
  404. mainAxisSize: MainAxisSize.min,
  405. children: [
  406. Container(
  407. height: 10,
  408. width: 15,
  409. margin: EdgeInsets.only(right: 3),
  410. child: Image.asset('lib/images/eyes2.png')
  411. ),
  412. Container(
  413. child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Colors.white,decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,),
  414. )
  415. ],
  416. ),
  417. padding: EdgeInsets.only(left: 8,right: 8),
  418. ),
  419. _dataArray[index]['type']==0?Container(
  420. margin: EdgeInsets.only(left: (MediaQuery.of(context).size.width-25)/2-30,
  421. top: (MediaQuery.of(context).size.width-25)/2/(double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}'))-30),
  422. height: 20,
  423. width: 20,
  424. child: Icon(Icons.play_circle_filled,color: Colors.white,),
  425. ):Container()
  426. ],
  427. ),
  428. );
  429. },
  430. staggeredTileBuilder: (index) =>StaggeredTile.fit(2),
  431. padding: EdgeInsets.only(top: 10),
  432. ),
  433. )
  434. ],
  435. ),
  436. ),
  437. ),
  438. );
  439. }
  440. _showEditMsgView() async{
  441. showModalBottomSheet(
  442. backgroundColor: Colors.transparent,
  443. isScrollControlled: true,
  444. context: context,
  445. builder: (context){
  446. return Container(
  447. height: MediaQuery.of(context).size.height*0.8,
  448. width: MediaQuery.of(context).size.width,
  449. decoration: BoxDecoration(
  450. color: Colors.white,
  451. borderRadius: BorderRadius.all(Radius.circular(10))
  452. ),
  453. child: SingleChildScrollView(
  454. child: Column(
  455. children: [
  456. Container(
  457. height: hsp(112),
  458. padding: EdgeInsets.only(left: wsp(33),right: wsp(33)),
  459. child: Row(
  460. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  461. children: [
  462. GestureDetector(
  463. child: Text('取消',style: TextStyle(fontSize: zsp(34),color: Color(0xFF000000)),),
  464. onTap: (){
  465. Navigator.pop(context);
  466. },
  467. ),
  468. Text('保存',style: TextStyle(fontSize: zsp(34),color: Color(0xFF007AFF)),)
  469. ],
  470. ),
  471. ),
  472. Divider(color: Color(0xFFE5E5E5),height: hsp(1),thickness: hsp(1),),
  473. Container(
  474. child: ListView.separated(
  475. shrinkWrap: true,
  476. itemBuilder: (context,index){
  477. return Container(
  478. height: index==0?hsp(112):hsp(92),
  479. padding: EdgeInsets.only(left: wsp(33),right: wsp(33)),
  480. child: Row(
  481. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  482. children: [
  483. Text('标题',style: TextStyle(fontSize: zsp(32),color: Color(0xFF000000)),),
  484. index==0?Container(
  485. height: hsp(80),
  486. width: hsp(80),
  487. decoration: BoxDecoration(
  488. color: Colors.black12,
  489. borderRadius: BorderRadius.all(Radius.circular(hsp(40))),
  490. ),
  491. ):index==1||index==2?Text('UNI王一博',style: TextStyle(fontSize: zsp(32),color: Color(0xFF9A9A9A)),
  492. ):Row(
  493. children: [
  494. Text('陕西 西安',style: TextStyle(fontSize: zsp(32),color: Color(0xFF9A9A9A))),
  495. Icon(Icons.chevron_right,size: hsp(40),color: Color(0xFF9A9A9A))
  496. ],
  497. )
  498. ],
  499. ),
  500. );
  501. },
  502. separatorBuilder: (context,index){
  503. return Divider(color: Color(0xFFE5E5E5),height: hsp(1),thickness: hsp(1),);
  504. },
  505. itemCount: 5,
  506. physics: NeverScrollableScrollPhysics(),
  507. ),
  508. ),
  509. Divider(color: Color(0xFFE5E5E5),height: hsp(1),thickness: hsp(1),),
  510. Container(
  511. padding: EdgeInsets.all(hsp(33)),
  512. child: Column(
  513. crossAxisAlignment: CrossAxisAlignment.start,
  514. children: [
  515. Text('标题',style: TextStyle(fontSize: zsp(32),color: Color(0xFF000000)),),
  516. Container(height: hsp(10),),
  517. Text('歌手、演员、主持人男子演唱组合UNIQ成员,职业摩托车赛车手',style: TextStyle(fontSize: zsp(30),color: Color(0xFF9A9A9A)),),
  518. ],
  519. ),
  520. ),
  521. Divider(color: Color(0xFFE5E5E5),height: hsp(1),thickness: hsp(1),),
  522. ],
  523. ),
  524. ),
  525. );
  526. });
  527. }
  528. _getUserInfoData() async{
  529. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/community',parameter: {},isLoading: true,isToken: true);
  530. if(dict!=null){
  531. _refresh();
  532. setState(() {
  533. _dict = dict['data'];
  534. });
  535. }
  536. }
  537. Future<void> _refresh() async{
  538. _page = 1;
  539. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/look',parameter: {'pageNo':_page,'pageSize':10,'type':_selected},isLoading: false,isToken: true);
  540. if(dict!=null){
  541. setState(() {
  542. _dataArray.addAll(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',parameter: {'pageNo':_page,'pageSize':10,'type':_selected},isLoading: false,isToken: true);
  549. if(dict!=null){
  550. setState(() {
  551. _dataArray.addAll(dict['data']['resultList']);
  552. });
  553. }
  554. }
  555. _postAgreementData(int index) async{
  556. Map request = {'type':1};
  557. if(_dataArray[index]['type']==0){
  558. request['squareId'] = _dataArray[index]['id'];
  559. }else{
  560. request['topicId'] = _dataArray[index]['id'];
  561. }
  562. Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/piazza/SquareCommunity/likeAndCollect',parameter: request,isLoading: false,isToken: true,refresh: (){
  563. });
  564. if(dict!=null){
  565. setState(() {
  566. _dataArray[index]['likeStatus'] = dict['data'];
  567. if(dict['data'] == 0){
  568. _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') - 1;
  569. }else{
  570. _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') + 1;
  571. }
  572. });
  573. }
  574. }
  575. }