YSCollection.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  4. import 'package:flutterappfuyou/code/version2/YSUrlPage.dart';
  5. import 'base/YSBase.dart';
  6. class YSCollection extends StatefulWidget {
  7. @override
  8. _YSCollectionState createState() => _YSCollectionState();
  9. }
  10. class _YSCollectionState extends State<YSCollection> {
  11. List _dataArray = [];
  12. ScrollController _scroll = ScrollController();
  13. int index;
  14. @override
  15. void initState() {
  16. Future.delayed(Duration(seconds: 0)).then((value){
  17. _refreshData();
  18. _scroll.addListener(() {
  19. if(_scroll.position.pixels == _scroll.position.maxScrollExtent){
  20. this._loadMoreData();
  21. }
  22. });
  23. });
  24. super.initState();
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. return YSBase(
  29. ystitle: '收藏',
  30. yschild: Container(
  31. color: Colors.white,
  32. height: MediaQuery.of(context).size.height-125,
  33. child: RefreshIndicator(
  34. onRefresh: _refreshData,
  35. child: _dataArray.length==0?Container(
  36. alignment: Alignment.center,
  37. child: Image.asset('lib/images/none.png',height: 200,width: 200,),
  38. ):ListView.separated(
  39. itemBuilder: (context,index){
  40. Map item = _dataArray[index];
  41. return GestureDetector(
  42. onTap: (){
  43. Navigator.of(context,rootNavigator: true).push(
  44. CupertinoPageRoute(builder: (context){
  45. return YSUrlPage(url: item['preview_url'],title: item['title'],wiki: item,isCollection: item['is_favorite']??false,);
  46. })
  47. ).then((value) {
  48. _refreshData();
  49. });
  50. },
  51. behavior: HitTestBehavior.opaque,
  52. child: item['covers'].length==1?Container(
  53. padding: EdgeInsets.all(10),
  54. child: Row(
  55. children: [
  56. Container(
  57. height: 70,
  58. width: 100,
  59. decoration: BoxDecoration(
  60. color: Color(0xFFF7CCC8),
  61. image: DecorationImage(
  62. fit: BoxFit.fill,
  63. image: NetworkImage('${_dataArray[index]['covers'][0]}')
  64. )
  65. ),
  66. ),
  67. Container(
  68. margin: EdgeInsets.only(left: 10),
  69. height: 70,
  70. width: MediaQuery.of(context).size.width-140,
  71. child: Column(
  72. crossAxisAlignment: CrossAxisAlignment.start,
  73. children: [
  74. Text('${_dataArray[index]['title']}',style: TextStyle(color: Color(0xFF0F0F0F),fontSize: 14,decoration: TextDecoration.none,fontWeight: FontWeight.w600),
  75. maxLines: 1,overflow: TextOverflow.ellipsis,textAlign: TextAlign.left,),
  76. Container(
  77. margin: EdgeInsets.only(top: 5,bottom: 10),
  78. child: Text(_dataArray[index]['contributor']??'',style: TextStyle(color: Color(0xFF0F0F0F),fontSize: 11,
  79. decoration: TextDecoration.none,fontWeight: FontWeight.normal),maxLines: 2,overflow: TextOverflow.ellipsis,),
  80. ),
  81. Text('${_dataArray[index]['created_at']}',style: TextStyle(color: Color(0xFF0F0F0F),fontSize: 11,
  82. decoration: TextDecoration.none,fontWeight: FontWeight.normal),maxLines: 2,overflow: TextOverflow.ellipsis,),
  83. ],
  84. ),
  85. )
  86. ],
  87. ),
  88. ):Container(
  89. padding: EdgeInsets.all(10),
  90. child: Column(
  91. crossAxisAlignment: CrossAxisAlignment.start,
  92. children: [
  93. Text('${_dataArray[index]['title']}',style: TextStyle(color: Color(0xFF0F0F0F),fontSize: 14,decoration: TextDecoration.none,fontWeight: FontWeight.w600),
  94. maxLines: 1,overflow: TextOverflow.ellipsis,textAlign: TextAlign.left,),
  95. Container(
  96. margin: EdgeInsets.only(top: 5,bottom: 5),
  97. child: Text('${_dataArray[index]['introduction']}',style: TextStyle(color: Color(0xFF0F0F0F),fontSize: 11,
  98. decoration: TextDecoration.none,fontWeight: FontWeight.normal),maxLines: 2,overflow: TextOverflow.ellipsis,),
  99. ),
  100. Row(
  101. children: [
  102. for(int i = 0;i<_dataArray[index]['covers'].length;i++)Container(
  103. height: 70,
  104. margin: EdgeInsets.only(right: 10),
  105. width: (MediaQuery.of(context).size.width-50)/3,
  106. decoration: BoxDecoration(
  107. color: Color(0xFFF7CCC8),
  108. image: DecorationImage(
  109. fit: BoxFit.fill,
  110. image: NetworkImage('${_dataArray[index]['covers'][i]}')
  111. )
  112. ),
  113. )
  114. ]
  115. )
  116. ],
  117. ),
  118. ),
  119. );
  120. },
  121. separatorBuilder: (context,index){
  122. return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE6E1E1),);
  123. },
  124. itemCount: _dataArray.length,
  125. physics: AlwaysScrollableScrollPhysics(),
  126. padding: EdgeInsets.all(0),
  127. controller: _scroll,
  128. ),
  129. ),
  130. ),
  131. );
  132. }
  133. Future<void> _refreshData() async{
  134. index = 1;
  135. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'wike/favoriteList', {'page':index});
  136. if(dict!=null){
  137. setState(() {
  138. _dataArray = dict['data'];
  139. });
  140. }
  141. }
  142. Future<void> _loadMoreData() async{
  143. index++;
  144. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'wike/favoriteList', {'page':index});
  145. if(dict!=null){
  146. setState(() {
  147. _dataArray.addAll(dict['data']);
  148. });
  149. }
  150. }
  151. }