import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:ysairplane/base/YSBase.dart'; import 'package:ysairplane/code/YSHomeMsgDetail.dart'; import 'package:ysairplane/code/YSHomeMsgSetting.dart'; import 'package:ysairplane/tools/YSNetWorking.dart'; import 'package:ysairplane/tools/YSTools.dart'; class YSHomeMsg extends StatefulWidget { @override _YSHomeMsgState createState() => _YSHomeMsgState(); } class _YSHomeMsgState extends State { int _page = 1; List _dataArray = []; @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _refreshData(); }); super.initState(); } @override Widget build(BuildContext context) { return YSBase( ystitle: '消息', ysright: GestureDetector( child: Icon(Icons.settings,size: hsp(40),color: Color(0xFF444444),), onTap: (){ Navigator.of(context).push( CupertinoPageRoute( builder: (context){ return YSHomeMsgSetting(); } ) ); }, ), yschild: Container( width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44, color: Color(0xFFF1F2F3), child: EasyRefresh( onRefresh: _refreshData, onLoad: _loadMore, header: TaurusHeader(), footer: TaurusFooter(), child: ListView.separated( padding: EdgeInsets.only(top: hsp(10),bottom: hsp(10)), shrinkWrap: true, itemBuilder: (context,index){ return GestureDetector( onTap: (){ setState(() { _dataArray[index]['isRead'] = 1; }); Navigator.of(context).push( CupertinoPageRoute( builder: (context){ return YSHomeMsgDetail(detailDict: _dataArray[index],); } ) ); }, child: Container( color: Color(0xFFFAFAFA), padding: EdgeInsets.all(hsp(30)), child: Row( children: [ Stack( children: [ Container( height: hsp(100), width: hsp(100), margin: EdgeInsets.only(top: hsp(5),right: wsp(20)), // decoration: BoxDecoration( // color: Color(0xFF3E81D0), // borderRadius: BorderRadius.all(Radius.circular(5)) // ), child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(5)), child: CachedNetworkImage( imageUrl: '${_dataArray[index]['ico']}', fit: BoxFit.fill, ), ), ), if(_dataArray[index]['isRead']==-1)Container( height: hsp(20), width: hsp(20), margin: EdgeInsets.only(left: hsp(85)), decoration: BoxDecoration( color: Color(0xFFE95D58), borderRadius: BorderRadius.all(Radius.circular(hsp(10))) ), ) ], ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: MediaQuery.of(context).size.width-hsp(160)-wsp(20), margin: EdgeInsets.only(bottom: hsp(10)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( child: Text('${_dataArray[index]['title']}',style: TextStyle(fontSize: zsp(32),color: Color(0xFF000000)), maxLines: 1,overflow: TextOverflow.ellipsis,), width: (MediaQuery.of(context).size.width-hsp(160)-wsp(20))*0.6, ), Text('${_dataArray[index]['createTime']}',style: TextStyle(fontSize: zsp(22),color: Color(0xFFCCCCCC)),), ], ), ), Container( child: Text('${_dataArray[index]['content']}',style: TextStyle(fontSize: zsp(28),color: Color(0xFF999999)),maxLines: 1,overflow: TextOverflow.ellipsis,), width: MediaQuery.of(context).size.width-hsp(160)-wsp(20), ) ], ) ], ), ), ); }, separatorBuilder: (context,index){ return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFF1F2F3),); }, itemCount: _dataArray.length ), ), ), ); } Future _refreshData() async{ _page = 1; Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/message/list',parameter: {'pageNum':_page,'pageSize':10}, isToken: true,refresh: (){_refreshData();}); if(dict!=null){ setState(() { _dataArray = dict['data']['resultList']; }); } } Future _loadMore() async{ _page++; Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/message/list',parameter: {'pageNum':_page,'pageSize':10}, isToken: true,refresh: (){_loadMore();}); if(dict!=null){ setState(() { _dataArray.addAll(dict['data']['resultList']); }); } } }