YSHomeMsg.dart 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter_easyrefresh/easy_refresh.dart';
  4. import 'package:ysairplane2/base/YSBase.dart';
  5. import 'package:ysairplane2/code/YSHomeMsgDetail.dart';
  6. import 'package:ysairplane2/code/YSHomeMsgSetting.dart';
  7. import 'package:ysairplane2/tools/YSNetWorking.dart';
  8. import 'package:ysairplane2/tools/YSTools.dart';
  9. class YSHomeMsg extends StatefulWidget {
  10. @override
  11. _YSHomeMsgState createState() => _YSHomeMsgState();
  12. }
  13. class _YSHomeMsgState extends State<YSHomeMsg> {
  14. int _page = 1;
  15. List _dataArray = [];
  16. @override
  17. void initState() {
  18. Future.delayed(Duration(seconds: 0)).then((value){
  19. _refreshData();
  20. });
  21. super.initState();
  22. }
  23. @override
  24. Widget build(BuildContext context) {
  25. return YSBase(
  26. ystitle: '消息',
  27. ysright: GestureDetector(
  28. child: Icon(Icons.settings,size: hsp(40),color: Color(0xFF444444),),
  29. onTap: (){
  30. Navigator.of(context).push(
  31. CupertinoPageRoute(
  32. builder: (context){
  33. return YSHomeMsgSetting();
  34. }
  35. )
  36. );
  37. },
  38. ),
  39. yschild: Container(
  40. width: MediaQuery.of(context).size.width,
  41. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44,
  42. color: Color(0xFFF1F2F3),
  43. child: EasyRefresh(
  44. onRefresh: _refreshData,
  45. onLoad: _loadMore,
  46. header: TaurusHeader(),
  47. footer: TaurusFooter(),
  48. child: ListView.separated(
  49. padding: EdgeInsets.only(top: hsp(10),bottom: hsp(10)),
  50. shrinkWrap: true,
  51. itemBuilder: (context,index){
  52. return GestureDetector(
  53. onTap: (){
  54. setState(() {
  55. _dataArray[index]['isRead'] = 1;
  56. });
  57. Navigator.of(context).push(
  58. CupertinoPageRoute(
  59. builder: (context){
  60. return YSHomeMsgDetail(detailDict: _dataArray[index],);
  61. }
  62. )
  63. );
  64. },
  65. child: Container(
  66. color: Color(0xFFFAFAFA),
  67. padding: EdgeInsets.all(hsp(30)),
  68. child: Row(
  69. children: [
  70. Stack(
  71. children: [
  72. Container(
  73. height: hsp(100),
  74. width: hsp(100),
  75. margin: EdgeInsets.only(top: hsp(5),right: wsp(20)),
  76. // decoration: BoxDecoration(
  77. // color: Color(0xFF3E81D0),
  78. // borderRadius: BorderRadius.all(Radius.circular(5))
  79. // ),
  80. child: ClipRRect(
  81. borderRadius: BorderRadius.all(Radius.circular(5)),
  82. child: ysImageLoad(
  83. imageUrl: '${_dataArray[index]['ico']}',
  84. fit: BoxFit.fill,
  85. height: hsp(100),
  86. width: hsp(100),
  87. ),
  88. ),
  89. ),
  90. if(_dataArray[index]['isRead']==-1)Container(
  91. height: hsp(20),
  92. width: hsp(20),
  93. margin: EdgeInsets.only(left: hsp(85)),
  94. decoration: BoxDecoration(
  95. color: Color(0xFFE95D58),
  96. borderRadius: BorderRadius.all(Radius.circular(hsp(10)))
  97. ),
  98. )
  99. ],
  100. ),
  101. Column(
  102. crossAxisAlignment: CrossAxisAlignment.start,
  103. children: [
  104. Container(
  105. width: MediaQuery.of(context).size.width-hsp(160)-wsp(20),
  106. margin: EdgeInsets.only(bottom: hsp(10)),
  107. child: Row(
  108. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  109. children: [
  110. Container(
  111. child: Text('${_dataArray[index]['title']}',style: TextStyle(fontSize: zsp(32),color: Color(0xFF000000)),
  112. maxLines: 1,overflow: TextOverflow.ellipsis,),
  113. width: (MediaQuery.of(context).size.width-hsp(160)-wsp(20))*0.6,
  114. ),
  115. Text('${_dataArray[index]['createTime']}',style: TextStyle(fontSize: zsp(22),color: Color(0xFFCCCCCC)),),
  116. ],
  117. ),
  118. ),
  119. Container(
  120. child: Text('${_dataArray[index]['content']}',style: TextStyle(fontSize: zsp(28),color: Color(0xFF999999)),maxLines: 1,overflow: TextOverflow.ellipsis,),
  121. width: MediaQuery.of(context).size.width-hsp(160)-wsp(20),
  122. )
  123. ],
  124. )
  125. ],
  126. ),
  127. ),
  128. );
  129. },
  130. separatorBuilder: (context,index){
  131. return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFF1F2F3),);
  132. },
  133. itemCount: _dataArray.length
  134. ),
  135. ),
  136. ),
  137. );
  138. }
  139. Future<void> _refreshData() async{
  140. _page = 1;
  141. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/message/list',parameter: {'pageNum':_page,'pageSize':10},
  142. isToken: true,refresh: (){_refreshData();});
  143. if(dict!=null){
  144. setState(() {
  145. _dataArray = dict['data']['resultList'];
  146. });
  147. }
  148. }
  149. Future<void> _loadMore() async{
  150. _page++;
  151. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/message/list',parameter: {'pageNum':_page,'pageSize':10},
  152. isToken: true,refresh: (){_loadMore();});
  153. if(dict!=null){
  154. setState(() {
  155. _dataArray.addAll(dict['data']['resultList']);
  156. });
  157. }
  158. }
  159. }