YSCollection.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter_easyrefresh/easy_refresh.dart';
  4. import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
  5. import 'package:ysairplane2/base/YSBase.dart';
  6. import 'package:ysairplane2/tools/YSNetWorking.dart';
  7. import 'YSAuthorSquare.dart';
  8. import 'YSSquareArticle.dart';
  9. import 'YSSquareVideo.dart';
  10. class YSCollection extends StatefulWidget {
  11. @override
  12. _YSCollectionState createState() => _YSCollectionState();
  13. }
  14. class _YSCollectionState extends State<YSCollection> {
  15. List _dataArray = [];
  16. int _page = 1;
  17. ScrollController _scrollController = ScrollController();
  18. @override
  19. void initState() {
  20. Future.delayed(Duration(seconds: 0)).then((value){
  21. _refreshData();
  22. });
  23. super.initState();
  24. }
  25. @override
  26. Widget build(BuildContext context) {
  27. return YSBase(
  28. ystitle: '收藏',
  29. yschild: Container(
  30. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44,
  31. width: MediaQuery.of(context).size.width,
  32. color: Color(0xFFF5F6F8),
  33. child: EasyRefresh(
  34. onRefresh: _refreshData,
  35. onLoad: _loadMore,
  36. header: TaurusHeader(
  37. ),
  38. footer: TaurusFooter(
  39. ),
  40. child: StaggeredGridView.countBuilder(
  41. controller: _scrollController,
  42. crossAxisCount: 4,
  43. crossAxisSpacing: 8,
  44. mainAxisSpacing: 8,
  45. itemCount: _dataArray.length,
  46. itemBuilder: (context, index) {
  47. return GestureDetector(
  48. onTap: (){
  49. Navigator.of(context,rootNavigator: true).push(
  50. CupertinoPageRoute(
  51. builder: (context){
  52. return _dataArray[index]['type']==1?YSSquareArticle(squareId: _dataArray[index]['id'],typeId: _dataArray[index]['type'],)
  53. :YSSquareVideo(squareId: _dataArray[index]['id'],typeId: _dataArray[index]['type'],);
  54. }
  55. )
  56. );
  57. },
  58. child: Stack(
  59. children: [
  60. Container(
  61. color: Colors.white,
  62. child:Column(
  63. children: [
  64. ysImageLoad(
  65. imageUrl: _dataArray[index]['type']==0?'${_dataArray[index]['coverPath']}':'${_dataArray[index]['topicCover']}',
  66. fit: BoxFit.fill,
  67. aspectRatio: double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}')
  68. ),
  69. Container(
  70. child: Text(_dataArray[index]['type']==0?'${_dataArray[index]['videoTitle']}':'${_dataArray[index]['topicTitle']}',
  71. style: TextStyle(fontSize: 13,color: Color(0xFF333333),decoration: TextDecoration.none,),maxLines: 2,overflow: TextOverflow.ellipsis,),
  72. padding: EdgeInsets.all(5),
  73. alignment: Alignment.centerLeft,
  74. ),
  75. Container(
  76. child: Row(
  77. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  78. children: [
  79. GestureDetector(
  80. behavior: HitTestBehavior.opaque,
  81. child: Row(
  82. children: [
  83. Container(
  84. height: 20,
  85. width: 20,
  86. margin: EdgeInsets.only(right: 5),
  87. decoration: BoxDecoration(
  88. color: Colors.black12,
  89. borderRadius: BorderRadius.all(Radius.circular(10)),
  90. ),
  91. child: ClipRRect(
  92. borderRadius: BorderRadius.all(Radius.circular(10)),
  93. child: ysImageLoad(
  94. imageUrl: '${_dataArray[index]['user']['avatar']}',
  95. fit: BoxFit.fill,
  96. height: 20,
  97. width: 20,
  98. ),
  99. ),
  100. ),
  101. Container(
  102. width: 70,
  103. child: Text('${_dataArray[index]['user']['nickname']}',
  104. style: TextStyle(fontSize: 12,color: Color(0xFF333333),decoration: TextDecoration.none,),overflow: TextOverflow.ellipsis,),
  105. )
  106. ],
  107. ),
  108. onTap: (){
  109. Navigator.of(context,rootNavigator: true).push(
  110. CupertinoPageRoute(
  111. builder: (context){
  112. return YSAuthorSquare(authorId: int.parse('${_dataArray[index]['user']['id']}'),);
  113. }
  114. )
  115. );
  116. },
  117. ),
  118. GestureDetector(
  119. behavior: HitTestBehavior.opaque,
  120. child: Row(
  121. children: [
  122. Container(
  123. height: 15,
  124. width: 15,
  125. margin: EdgeInsets.only(right: 5),
  126. child: Image.asset(_dataArray[index]['likeStatus']==0?'lib/images/love.png':'lib/images/love2.png')
  127. ),
  128. Container(
  129. child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Color(0xFFEE564C),decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,),
  130. )
  131. ],
  132. mainAxisSize: MainAxisSize.min,
  133. ),
  134. onTap: (){
  135. _postAgreementData(index);
  136. },
  137. ),
  138. ],
  139. ),
  140. padding: EdgeInsets.only(left: 5,right: 5,top: 3,bottom: 5),
  141. ),
  142. ],
  143. ),
  144. ),
  145. Container(
  146. height: 15,
  147. margin: EdgeInsets.only(top: 10,left: 10),
  148. decoration: BoxDecoration(
  149. color: Colors.black12,
  150. borderRadius: BorderRadius.all(Radius.circular(7.5)),
  151. ),
  152. child: Row(
  153. mainAxisSize: MainAxisSize.min,
  154. children: [
  155. Container(
  156. height: 10,
  157. width: 15,
  158. margin: EdgeInsets.only(right: 3),
  159. child: Image.asset('lib/images/eyes2.png')
  160. ),
  161. Container(
  162. child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Colors.white,decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,),
  163. )
  164. ],
  165. ),
  166. padding: EdgeInsets.only(left: 8,right: 8),
  167. ),
  168. _dataArray[index]['type']==0?Container(
  169. margin: EdgeInsets.only(left: (MediaQuery.of(context).size.width-25)/2-30,
  170. top: (MediaQuery.of(context).size.width-25)/2/(double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}'))-30),
  171. height: 20,
  172. width: 20,
  173. child: Icon(Icons.play_circle_filled,color: Colors.white,),
  174. ):Container()
  175. ],
  176. ),
  177. );
  178. },
  179. staggeredTileBuilder: (index) =>StaggeredTile.fit(2),
  180. padding: EdgeInsets.only(top: 10),
  181. ),
  182. ),
  183. ),
  184. );
  185. }
  186. Future<void> _refreshData() async{
  187. _page = 1;
  188. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/myCollect',parameter: {'pageNo':_page,'pageSize':10},isToken: true,refresh: (){
  189. _refreshData();
  190. });
  191. if(dict!=null){
  192. setState(() {
  193. _dataArray = dict['data']['resultList'];
  194. });
  195. }
  196. }
  197. Future<void> _loadMore() async{
  198. _page++;
  199. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/myCollect',parameter: {'pageNo':_page,'pageSize':10},isToken: true,refresh: (){
  200. _loadMore();
  201. });
  202. if(dict!=null){
  203. setState(() {
  204. _dataArray.addAll(dict['data']['resultList']);
  205. });
  206. }
  207. }
  208. _postAgreementData(int index) async{
  209. Map request = {'type':1};
  210. if(_dataArray[index]['type']==0){
  211. request['squareId'] = _dataArray[index]['id'];
  212. }else{
  213. request['topicId'] = _dataArray[index]['id'];
  214. }
  215. Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/piazza/SquareCommunity/likeAndCollect',parameter: request,isLoading: false,isToken: true,refresh: (){
  216. });
  217. if(dict!=null){
  218. setState(() {
  219. _dataArray[index]['likeStatus'] = dict['data'];
  220. if(dict['data'] == 0){
  221. _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') - 1;
  222. }else{
  223. _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') + 1;
  224. }
  225. });
  226. }
  227. }
  228. }