YSInformation.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/base/YSTools.dart';
  5. import 'package:flutterappfuyou/code/version2/view/YSWikiListView.dart';
  6. import 'package:shared_preferences/shared_preferences.dart';
  7. import 'base/YSBase.dart';
  8. class YSInformation extends StatefulWidget {
  9. @override
  10. _YSInformationState createState() => _YSInformationState();
  11. }
  12. class _YSInformationState extends State<YSInformation> {
  13. ScrollController _scroll = ScrollController();
  14. TextEditingController _search = TextEditingController();
  15. int _index = 1;
  16. List _dataArray = [];
  17. @override
  18. void initState() {
  19. Future.delayed(Duration(seconds: 0)).then((value){
  20. this._refreshData();
  21. _scroll.addListener(() {
  22. if(_scroll.position.pixels == _scroll.position.maxScrollExtent){
  23. this._loadMoreData();
  24. }
  25. });
  26. });
  27. super.initState();
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return YSBase(
  32. ystitle: '育儿百科',
  33. yschild: SingleChildScrollView(
  34. child: Column(
  35. children: [
  36. // Container(
  37. // height: 50,
  38. // decoration: BoxDecoration(
  39. // color: Colors.white,
  40. // borderRadius: BorderRadius.only(topRight: Radius.circular(20),topLeft: Radius.circular(20)),
  41. // ),
  42. // padding: EdgeInsets.only(left: 20,right: 20,top: 10,bottom: 10),
  43. // child: CupertinoTextField(
  44. // placeholder: '搜索',
  45. // textAlign: TextAlign.center,
  46. // style: TextStyle(fontSize: 14,color: Color(0xFF808080),decoration: TextDecoration.none),
  47. // placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFF808080),decoration: TextDecoration.none),
  48. // decoration: BoxDecoration(
  49. // borderRadius: BorderRadius.all(Radius.circular(15)),
  50. // color: Color(0xFFF5F3F0)
  51. // ),
  52. // controller: _search,
  53. // textInputAction: TextInputAction.search,
  54. // onSubmitted: (value){
  55. // _refreshData();
  56. // },
  57. // ),
  58. // ),
  59. Container(
  60. color: Colors.white,
  61. height: MediaQuery.of(context).size.height-75,
  62. child: RefreshIndicator(
  63. onRefresh: _refreshData,
  64. child: _dataArray.length==0?Container(
  65. alignment: Alignment.center,
  66. child: Image.asset('lib/images/none.png',height: 200,width: 200,),
  67. ):ListView.separated(
  68. shrinkWrap: true,
  69. itemBuilder: (context,index){
  70. return GestureDetector(
  71. onTap: (){},
  72. behavior: HitTestBehavior.opaque,
  73. child: YSWikiListView(
  74. wikiItem: _dataArray[index],
  75. callback: (){
  76. _refreshData();
  77. },
  78. ),
  79. );
  80. },
  81. separatorBuilder: (context,index){
  82. return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE6E1E1),);
  83. },
  84. itemCount: _dataArray.length,
  85. physics: AlwaysScrollableScrollPhysics(),
  86. padding: EdgeInsets.only(left: 15,right: 15),
  87. controller: _scroll,
  88. ),
  89. ),
  90. ),
  91. ],
  92. ),
  93. physics: NeverScrollableScrollPhysics(),
  94. ),
  95. );
  96. }
  97. Future<void> _refreshData() async{
  98. SharedPreferences prefer = await SharedPreferences.getInstance();
  99. Map request = Map();
  100. _index = 1;
  101. request['page'] = _index;
  102. request['title'] = _search.text??'';
  103. request['category_id'] = prefer.getInt('chapters')+1;
  104. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'wike/list', request);
  105. if(dict!=null){
  106. setState(() {
  107. _dataArray = dict['data'];
  108. });
  109. }
  110. }
  111. Future<void> _loadMoreData() async{
  112. SharedPreferences prefer = await SharedPreferences.getInstance();
  113. Map request = Map();
  114. _index++;
  115. request['page'] = _index;
  116. request['title'] = _search.text??'';
  117. request['category_id'] = prefer.getInt('chapters')+1;
  118. Map dict = await ysRequestHttp(context, requestType.get, 'wike/list', request);
  119. if(dict!=null){
  120. setState(() {
  121. _dataArray.addAll(dict['data']);
  122. });
  123. }
  124. }
  125. }