YSAuthorSquare.dart 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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/tools/YSNetWorking.dart';
  6. import 'package:ysairplane/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 YSAuthorSquare extends StatefulWidget {
  11. final int authorId;
  12. const YSAuthorSquare({Key key, this.authorId}) : super(key: key);
  13. @override
  14. _YSAuthorSquareState createState() => _YSAuthorSquareState();
  15. }
  16. class _YSAuthorSquareState extends State<YSAuthorSquare> {
  17. ScrollController _scrollController = ScrollController();
  18. Map _dict;
  19. int _selected = 0;
  20. List _dataArray = [];
  21. int _page = 1;
  22. int _isAttention = 0;
  23. @override
  24. void initState() {
  25. Future.delayed(Duration(seconds: 0)).then((value){
  26. _getUserInfoData();
  27. });
  28. super.initState();
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. return Scaffold(
  33. backgroundColor: Colors.white,
  34. body: EasyRefresh(
  35. onRefresh: _refresh,
  36. onLoad: _loadMore,
  37. header: MaterialHeader(
  38. ),
  39. footer: BezierBounceFooter(
  40. backgroundColor: Colors.transparent,
  41. color: Colors.transparent,
  42. ),
  43. child: SingleChildScrollView(
  44. child: Stack(
  45. children: [
  46. Container(
  47. height: hsp(300)+MediaQuery.of(context).padding.top,
  48. width: MediaQuery.of(context).size.width,
  49. child: Image(
  50. image: _dict==null?AssetImage('lib/images/squareBg2.png'):NetworkImage('${_dict['backGroundUrl']}'),
  51. fit: BoxFit.fill,
  52. ),
  53. ),
  54. Container(
  55. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+10,left: 15,right: 15),
  56. height: 50,
  57. child: Row(
  58. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  59. children: [
  60. GestureDetector(
  61. child: Icon(Icons.arrow_back_ios,size: 20,color: Colors.white,),
  62. onTap: (){
  63. Navigator.pop(context);
  64. },
  65. ),
  66. ],
  67. ),
  68. ),
  69. Container(
  70. height: hsp(160),
  71. width: hsp(160),
  72. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(220),left: wsp(40)),
  73. decoration: BoxDecoration(
  74. image: DecorationImage(image: _dict==null?AssetImage('lib/images/head.png'):NetworkImage('${_dict['user']['avatar']}')),
  75. borderRadius: BorderRadius.all(Radius.circular(35))
  76. ),
  77. ),
  78. GestureDetector(
  79. onTap: (){
  80. _postAuthorAttention();
  81. },
  82. child: Container(
  83. height: hsp(60),
  84. width: wsp(160),
  85. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(314),left: MediaQuery.of(context).size.width-wsp(200)),
  86. decoration: BoxDecoration(
  87. color: _isAttention==0?Color(0xFFED4946):Color(0xFFBCBCBC),
  88. borderRadius: BorderRadius.all(Radius.circular(3))
  89. ),
  90. alignment: Alignment.center,
  91. child: Text(_isAttention==0?'+ 关注':'取消关注',style: TextStyle(color: Colors.white,fontSize: zsp(24)),),
  92. ),
  93. ),
  94. Container(
  95. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(400)),
  96. width: MediaQuery.of(context).size.width,
  97. child: Column(
  98. children: [
  99. Container(
  100. child: Column(
  101. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  102. crossAxisAlignment: CrossAxisAlignment.start,
  103. children: [
  104. Container(
  105. child: Row(
  106. children: [
  107. Text(_dict==null?'':(_dict['user']['nickname']).toString().length>10?(_dict['user']['nickname']).toString().substring(0,10)+'..':(_dict['user']['nickname']).toString(),
  108. style: TextStyle(fontSize: 16,color: Color(0xFF333333),fontWeight: FontWeight.bold,decoration: TextDecoration.none),maxLines: 1,overflow: TextOverflow.ellipsis,),
  109. Icon(Icons.pregnant_woman,color: Colors.pinkAccent,),
  110. ],
  111. ),
  112. ),
  113. Container(
  114. child: Text(_dict==null?'':'${_dict['labelIds']}',
  115. style: TextStyle(fontSize: 12,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none),),
  116. margin: EdgeInsets.only(top: hsp(20),bottom: hsp(20)),
  117. ),
  118. Row(
  119. children: [
  120. Container(
  121. child: Text('陕西西安',
  122. style: TextStyle(fontSize: 10,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  123. ),
  124. decoration: BoxDecoration(
  125. color: Color(0xFFEEEEEE),
  126. borderRadius: BorderRadius.all(Radius.circular(5))
  127. ),
  128. padding: EdgeInsets.all(5),
  129. margin: EdgeInsets.only(bottom: hsp(20)),
  130. ),
  131. Container(
  132. child: Text(_dict==null?'':'${_dict['user']['school']}',
  133. style: TextStyle(fontSize: 10,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  134. ),
  135. decoration: BoxDecoration(
  136. color: Color(0xFFEEEEEE),
  137. borderRadius: BorderRadius.all(Radius.circular(5))
  138. ),
  139. padding: EdgeInsets.all(5),
  140. margin: EdgeInsets.only(left: 5,bottom: hsp(20)),
  141. ),
  142. ],
  143. ),
  144. Row(
  145. children: [
  146. Column(
  147. children: [
  148. Text(_dict==null?'':'${_dict['attention']}',
  149. style: TextStyle(fontSize: 14,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  150. ),
  151. Text('关注',
  152. style: TextStyle(fontSize: 12,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  153. )
  154. ],
  155. ),
  156. Container(
  157. margin: EdgeInsets.only(left: wsp(50),right: wsp(50)),
  158. child: Column(
  159. children: [
  160. Text(_dict==null?'':'${_dict['fans']}',
  161. style: TextStyle(fontSize: 14,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  162. ),
  163. Text('粉丝',
  164. style: TextStyle(fontSize: 12,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  165. )
  166. ],
  167. ),
  168. ),
  169. Column(
  170. children: [
  171. Text(_dict==null?'':'${_dict['likeCount']}',
  172. style: TextStyle(fontSize: 14,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  173. ),
  174. Text('喜欢',
  175. style: TextStyle(fontSize: 12,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none),
  176. )
  177. ],
  178. ) ],
  179. ),
  180. ],
  181. ),
  182. padding: EdgeInsets.only(left: wsp(50),right: wsp(50),bottom: hsp(10)),
  183. ),
  184. Divider(color: Color(0xFFF4F4F4),height: hsp(40),thickness: hsp(10),),
  185. Container(
  186. width: MediaQuery.of(context).size.width,
  187. height: hsp(77),
  188. color: Colors.white,
  189. padding: EdgeInsets.only(left: 20,right: 20),
  190. child: ListView.separated(
  191. scrollDirection: Axis.horizontal,
  192. itemBuilder: (context,index){
  193. return GestureDetector(
  194. onTap: (){
  195. _selected = index;
  196. _refresh();
  197. },
  198. child: Container(
  199. height: hsp(70),
  200. width: (MediaQuery.of(context).size.width-80)/3,
  201. child: Column(
  202. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  203. children: [
  204. Text(index==0?'作品':index==1?'关注':'收藏',style: TextStyle(fontSize: 16,color: index==_selected?Color(0xFF333333):Color(0xFF666666),decoration: TextDecoration.none,
  205. fontWeight: index==_selected?FontWeight.bold:FontWeight.normal),),
  206. Container(height: 2,width: wsp(30),color: index==_selected?Color(0xFF333333):Colors.transparent,)
  207. ],
  208. ),
  209. ),
  210. );
  211. },
  212. separatorBuilder: (context,index){
  213. return Container(width: 20,);
  214. },
  215. itemCount: 3
  216. ),
  217. ),
  218. Divider(color: Color(0xFFF4F4F4),height: hsp(2),thickness: hsp(2),),
  219. Container(
  220. margin: EdgeInsets.only(left: 10,right: 10),
  221. child: StaggeredGridView.countBuilder(
  222. shrinkWrap: true,
  223. controller: _scrollController,
  224. crossAxisCount: 4,
  225. crossAxisSpacing: 8,
  226. mainAxisSpacing: 8,
  227. itemCount: _dataArray.length,
  228. itemBuilder: (context, index) {
  229. return GestureDetector(
  230. onTap: (){
  231. Navigator.of(context,rootNavigator: true).push(
  232. CupertinoPageRoute(
  233. builder: (context){
  234. return _dataArray[index]['type']==1?YSSquareArticle(squareId: _dataArray[index]['id'],typeId: _dataArray[index]['type'],)
  235. :YSSquareVideo(squareId: _dataArray[index]['id'],typeId: _dataArray[index]['type'],);
  236. }
  237. )
  238. );
  239. },
  240. child: Stack(
  241. children: [
  242. Container(
  243. color: Colors.white,
  244. child:Column(
  245. children: [
  246. AspectRatio(
  247. child: Container(
  248. decoration: BoxDecoration(
  249. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)),
  250. ),
  251. child: ClipRRect(
  252. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)),
  253. child: CachedNetworkImage(
  254. imageUrl: _dataArray[index]['type']==0?'${_dataArray[index]['coverPath']}':'${_dataArray[index]['topicCover']}',
  255. fit: BoxFit.fill
  256. ),
  257. ),
  258. ),
  259. aspectRatio: double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}')
  260. ),
  261. Container(
  262. child: Text(_dataArray[index]['type']==0?'${_dataArray[index]['videoTitle']}':'${_dataArray[index]['topicTitle']}',
  263. style: TextStyle(fontSize: 13,color: Color(0xFF333333),decoration: TextDecoration.none,),maxLines: 2,overflow: TextOverflow.ellipsis,),
  264. padding: EdgeInsets.all(5),
  265. alignment: Alignment.centerLeft,
  266. ),
  267. Container(
  268. child: Row(
  269. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  270. children: [
  271. Row(
  272. children: [
  273. Container(
  274. height: 20,
  275. width: 20,
  276. margin: EdgeInsets.only(right: 5),
  277. decoration: BoxDecoration(
  278. color: Colors.black12,
  279. borderRadius: BorderRadius.all(Radius.circular(10)),
  280. ),
  281. child: ClipRRect(
  282. borderRadius: BorderRadius.all(Radius.circular(10)),
  283. child: CachedNetworkImage(
  284. imageUrl: '${_dataArray[index]['user']['avatar']}',
  285. fit: BoxFit.fill,
  286. ),
  287. ),
  288. ),
  289. Container(
  290. width: 70,
  291. child: Text('${_dataArray[index]['user']['nickname']}',
  292. style: TextStyle(fontSize: 12,color: Color(0xFF333333),decoration: TextDecoration.none,),overflow: TextOverflow.ellipsis,),
  293. )
  294. ],
  295. ),
  296. GestureDetector(
  297. behavior: HitTestBehavior.opaque,
  298. child: Row(
  299. children: [
  300. Container(
  301. height: 15,
  302. width: 15,
  303. margin: EdgeInsets.only(right: 5),
  304. child: Image.asset(_dataArray[index]['likeStatus']==0?'lib/images/love.png':'lib/images/love2.png')
  305. ),
  306. Container(
  307. child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Color(0xFFEE564C),decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,),
  308. )
  309. ],
  310. mainAxisSize: MainAxisSize.min,
  311. ),
  312. onTap: (){
  313. _postAgreementData(index);
  314. },
  315. ),
  316. ],
  317. ),
  318. padding: EdgeInsets.only(left: 5,right: 5,top: 3,bottom: 5),
  319. ),
  320. ],
  321. ),
  322. ),
  323. Container(
  324. height: 15,
  325. margin: EdgeInsets.only(top: 10,left: 10),
  326. decoration: BoxDecoration(
  327. color: Colors.black12,
  328. borderRadius: BorderRadius.all(Radius.circular(7.5)),
  329. ),
  330. child: Row(
  331. mainAxisSize: MainAxisSize.min,
  332. children: [
  333. Container(
  334. height: 10,
  335. width: 15,
  336. margin: EdgeInsets.only(right: 3),
  337. child: Image.asset('lib/images/eyes2.png')
  338. ),
  339. Container(
  340. child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Colors.white,decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,),
  341. )
  342. ],
  343. ),
  344. padding: EdgeInsets.only(left: 8,right: 8),
  345. ),
  346. _dataArray[index]['type']==0?Container(
  347. margin: EdgeInsets.only(left: (MediaQuery.of(context).size.width-25)/2-30,
  348. top: (MediaQuery.of(context).size.width-25)/2/(double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}'))-30),
  349. height: 20,
  350. width: 20,
  351. child: Icon(Icons.play_circle_filled,color: Colors.white,),
  352. ):Container()
  353. ],
  354. ),
  355. );
  356. },
  357. staggeredTileBuilder: (index) =>StaggeredTile.fit(2),
  358. padding: EdgeInsets.only(top: 10),
  359. ),
  360. )
  361. ],
  362. ),
  363. )
  364. ],
  365. ),
  366. ),
  367. ),
  368. );
  369. }
  370. _getUserInfoData() async{
  371. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/community',parameter: {'userId':widget.authorId},isLoading: true,isToken: true);
  372. if(dict!=null){
  373. _refresh();
  374. setState(() {
  375. _dict = dict['data'];
  376. _isAttention = _dict['isAttention'];
  377. });
  378. }
  379. }
  380. Future<void> _refresh() async{
  381. _page = 1;
  382. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/look',parameter: {'pageNo':_page,'pageSize':10,'type':_selected,'userId':widget.authorId},isLoading: false,isToken: true);
  383. if(dict!=null){
  384. setState(() {
  385. _dataArray = dict['data']['resultList'];
  386. });
  387. }
  388. }
  389. Future<void> _loadMore() async{
  390. _page++;
  391. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/look',parameter: {'pageNo':_page,'pageSize':10,'type':_selected,'userId':widget.authorId},isLoading: false,isToken: true);
  392. if(dict!=null){
  393. setState(() {
  394. _dataArray.addAll(dict['data']['resultList']);
  395. });
  396. }
  397. }
  398. _postAgreementData(int index) async{
  399. Map request = {'type':1};
  400. if(_dataArray[index]['type']==0){
  401. request['squareId'] = _dataArray[index]['id'];
  402. }else{
  403. request['topicId'] = _dataArray[index]['id'];
  404. }
  405. Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/piazza/SquareCommunity/likeAndCollect',parameter: request,isLoading: false,isToken: true,refresh: (){
  406. });
  407. if(dict!=null){
  408. setState(() {
  409. _dataArray[index]['likeStatus'] = dict['data'];
  410. if(dict['data'] == 0){
  411. _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') - 1;
  412. }else{
  413. _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') + 1;
  414. }
  415. });
  416. }
  417. }
  418. _postAuthorAttention() async{
  419. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/attention',
  420. parameter: {'userId':widget.authorId},isLoading: false,isToken: true,refresh: _postAuthorAttention);
  421. if(dict!=null){
  422. setState(() {
  423. _isAttention = dict['data'];
  424. });
  425. }
  426. }
  427. }