YSAuthorSquare.dart 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. setState(() {
  196. _selected = index;
  197. });
  198. },
  199. child: Container(
  200. height: hsp(70),
  201. width: (MediaQuery.of(context).size.width-80)/3,
  202. child: Column(
  203. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  204. children: [
  205. Text(index==0?'作品':index==1?'关注':'收藏',style: TextStyle(fontSize: 16,color: index==_selected?Color(0xFF333333):Color(0xFF666666),decoration: TextDecoration.none,
  206. fontWeight: index==_selected?FontWeight.bold:FontWeight.normal),),
  207. Container(height: 2,width: wsp(30),color: index==_selected?Color(0xFF333333):Colors.transparent,)
  208. ],
  209. ),
  210. ),
  211. );
  212. },
  213. separatorBuilder: (context,index){
  214. return Container(width: 20,);
  215. },
  216. itemCount: 3
  217. ),
  218. ),
  219. Divider(color: Color(0xFFF4F4F4),height: hsp(2),thickness: hsp(2),),
  220. Container(
  221. margin: EdgeInsets.only(left: 10,right: 10),
  222. child: StaggeredGridView.countBuilder(
  223. shrinkWrap: true,
  224. controller: _scrollController,
  225. crossAxisCount: 4,
  226. crossAxisSpacing: 8,
  227. mainAxisSpacing: 8,
  228. itemCount: _dataArray.length,
  229. itemBuilder: (context, index) {
  230. return GestureDetector(
  231. onTap: (){
  232. Navigator.of(context,rootNavigator: true).push(
  233. CupertinoPageRoute(
  234. builder: (context){
  235. return _dataArray[index]['type']==1?YSSquareArticle(squareId: _dataArray[index]['id'],typeId: _dataArray[index]['type'],)
  236. :YSSquareVideo(squareId: _dataArray[index]['id'],typeId: _dataArray[index]['type'],);
  237. }
  238. )
  239. );
  240. },
  241. child: Stack(
  242. children: [
  243. Container(
  244. color: Colors.white,
  245. child:Column(
  246. children: [
  247. AspectRatio(
  248. child: Container(
  249. decoration: BoxDecoration(
  250. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)),
  251. ),
  252. child: ClipRRect(
  253. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)),
  254. child: CachedNetworkImage(
  255. imageUrl: _dataArray[index]['type']==0?'${_dataArray[index]['coverPath']}':'${_dataArray[index]['topicCover']}',
  256. fit: BoxFit.fill
  257. ),
  258. ),
  259. ),
  260. aspectRatio: double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}')
  261. ),
  262. Container(
  263. child: Text(_dataArray[index]['type']==0?'${_dataArray[index]['videoTitle']}':'${_dataArray[index]['topicTitle']}',
  264. style: TextStyle(fontSize: 13,color: Color(0xFF333333),decoration: TextDecoration.none,),maxLines: 2,overflow: TextOverflow.ellipsis,),
  265. padding: EdgeInsets.all(5),
  266. alignment: Alignment.centerLeft,
  267. ),
  268. Container(
  269. child: Row(
  270. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  271. children: [
  272. Row(
  273. children: [
  274. Container(
  275. height: 20,
  276. width: 20,
  277. margin: EdgeInsets.only(right: 5),
  278. decoration: BoxDecoration(
  279. color: Colors.black12,
  280. borderRadius: BorderRadius.all(Radius.circular(10)),
  281. ),
  282. child: ClipRRect(
  283. borderRadius: BorderRadius.all(Radius.circular(10)),
  284. child: CachedNetworkImage(
  285. imageUrl: '${_dataArray[index]['user']['avatar']}',
  286. fit: BoxFit.fill,
  287. ),
  288. ),
  289. ),
  290. Container(
  291. width: 70,
  292. child: Text('${_dataArray[index]['user']['nickname']}',
  293. style: TextStyle(fontSize: 12,color: Color(0xFF333333),decoration: TextDecoration.none,),overflow: TextOverflow.ellipsis,),
  294. )
  295. ],
  296. ),
  297. GestureDetector(
  298. behavior: HitTestBehavior.opaque,
  299. child: Row(
  300. children: [
  301. Container(
  302. height: 15,
  303. width: 15,
  304. margin: EdgeInsets.only(right: 5),
  305. child: Image.asset(_dataArray[index]['likeStatus']==0?'lib/images/love.png':'lib/images/love2.png')
  306. ),
  307. Container(
  308. child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Color(0xFFEE564C),decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,),
  309. )
  310. ],
  311. mainAxisSize: MainAxisSize.min,
  312. ),
  313. onTap: (){
  314. _postAgreementData(index);
  315. },
  316. ),
  317. ],
  318. ),
  319. padding: EdgeInsets.only(left: 5,right: 5,top: 3,bottom: 5),
  320. ),
  321. ],
  322. ),
  323. ),
  324. Container(
  325. height: 15,
  326. margin: EdgeInsets.only(top: 10,left: 10),
  327. decoration: BoxDecoration(
  328. color: Colors.black12,
  329. borderRadius: BorderRadius.all(Radius.circular(7.5)),
  330. ),
  331. child: Row(
  332. mainAxisSize: MainAxisSize.min,
  333. children: [
  334. Container(
  335. height: 10,
  336. width: 15,
  337. margin: EdgeInsets.only(right: 3),
  338. child: Image.asset('lib/images/eyes2.png')
  339. ),
  340. Container(
  341. child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Colors.white,decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,),
  342. )
  343. ],
  344. ),
  345. padding: EdgeInsets.only(left: 8,right: 8),
  346. ),
  347. _dataArray[index]['type']==0?Container(
  348. margin: EdgeInsets.only(left: (MediaQuery.of(context).size.width-25)/2-30,
  349. top: (MediaQuery.of(context).size.width-25)/2/(double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}'))-30),
  350. height: 20,
  351. width: 20,
  352. child: Icon(Icons.play_circle_filled,color: Colors.white,),
  353. ):Container()
  354. ],
  355. ),
  356. );
  357. },
  358. staggeredTileBuilder: (index) =>StaggeredTile.fit(2),
  359. padding: EdgeInsets.only(top: 10),
  360. ),
  361. )
  362. ],
  363. ),
  364. )
  365. ],
  366. ),
  367. ),
  368. ),
  369. );
  370. }
  371. _getUserInfoData() async{
  372. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/community',parameter: {'userId':widget.authorId},isLoading: true,isToken: true);
  373. if(dict!=null){
  374. _refresh();
  375. setState(() {
  376. _dict = dict['data'];
  377. _isAttention = _dict['isAttention'];
  378. });
  379. }
  380. }
  381. Future<void> _refresh() async{
  382. _page = 1;
  383. 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);
  384. if(dict!=null){
  385. setState(() {
  386. _dataArray.addAll(dict['data']['resultList']);
  387. });
  388. }
  389. }
  390. Future<void> _loadMore() async{
  391. _page++;
  392. 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);
  393. if(dict!=null){
  394. setState(() {
  395. _dataArray.addAll(dict['data']['resultList']);
  396. });
  397. }
  398. }
  399. _postAgreementData(int index) async{
  400. Map request = {'type':1};
  401. if(_dataArray[index]['type']==0){
  402. request['squareId'] = _dataArray[index]['id'];
  403. }else{
  404. request['topicId'] = _dataArray[index]['id'];
  405. }
  406. Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/piazza/SquareCommunity/likeAndCollect',parameter: request,isLoading: false,isToken: true,refresh: (){
  407. });
  408. if(dict!=null){
  409. setState(() {
  410. _dataArray[index]['likeStatus'] = dict['data'];
  411. if(dict['data'] == 0){
  412. _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') - 1;
  413. }else{
  414. _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') + 1;
  415. }
  416. });
  417. }
  418. }
  419. _postAuthorAttention() async{
  420. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/attention',parameter: {'userId':widget.authorId},isLoading: false,isToken: true,refresh: (){
  421. });
  422. if(dict!=null){
  423. setState(() {
  424. _isAttention = dict['data'];
  425. });
  426. }
  427. }
  428. }