YSHomeMsg.dart 6.3 KB

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