YSAuthorSquare.dart 22 KB

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