import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:ysairplane2/tools/YSNetWorking.dart'; import 'package:ysairplane2/tools/YSTools.dart'; import 'YSSquareArticle.dart'; import 'YSSquareVideo.dart'; class YSMessage extends StatefulWidget { @override _YSMessageState createState() => _YSMessageState(); } class _YSMessageState extends State { bool _isShow = false; int _index = 0; List _types = []; List _dataArray = []; int _page = 1; @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _getTypeData(); }); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Color(0xFFF0F0F1), appBar: CupertinoNavigationBar( backgroundColor: Colors.white, leading: GestureDetector(child: Icon(Icons.arrow_back_ios,size: 15,color: Color(0xFF000000),),onTap: (){Navigator.pop(context);},), border: Border(), middle: GestureDetector( onTap: (){ setState(() { _isShow = !_isShow; }); }, child: Row( mainAxisSize: MainAxisSize.min, children: [ Text(_types.length>0?'${_types[_index]['name']}':'',style: TextStyle(fontSize: zsp(36),color: Color(0xFF000000)),), Icon(Icons.keyboard_arrow_down,size: 15,color: Color(0xFF000000),), ], ), ), ), body: Stack( children: [ EasyRefresh( onRefresh: _refresh, onLoad: _loadMore, header: TaurusHeader( ), footer: TaurusFooter( ), child: ListView.separated( shrinkWrap: true, itemBuilder: (context,index){ return Container( padding: EdgeInsets.all(hsp(30)), color: Colors.white, child: _dataArray[index]['type']=='4'?Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('系统消息',style: TextStyle(fontSize: zsp(28),color: Color(0xFF3C61B2),fontWeight: FontWeight.bold),), Container( child: Text('${_dataArray[index]['createTime']}',style: TextStyle(fontSize: zsp(22),color: Color(0xFF9A9A9A)),), margin: EdgeInsets.only(top: hsp(10),bottom: hsp(20)), ), Container( child: Text('${_dataArray[index]['content']}',style: TextStyle(fontSize: zsp(28),color: Color(0xFF343434)),), width: MediaQuery.of(context).size.width-hsp(170), ) ], ):_dataArray[index]['type']=='2'?Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Container( height: hsp(66), width: hsp(66), decoration: BoxDecoration( color: Colors.lightBlue, borderRadius: BorderRadius.all(Radius.circular(hsp(33))) ), margin: EdgeInsets.only(right: wsp(20)), child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(hsp(33))), child: ysImageLoad( imageUrl: '${_dataArray[index]['users']['avatar']}', fit: BoxFit.fill, height: hsp(66), width: hsp(66), ), ), ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ RichText( text: TextSpan( text: '${_dataArray[index]['users']['nickname']}', style: TextStyle(fontSize: zsp(22),color: Color(0xFF3C61B2),fontWeight: FontWeight.bold), children: [ TextSpan( text: ' ${_dataArray[index]['content']}', style: TextStyle(color: Color(0xFF575757),fontWeight: FontWeight.normal), ) ] ), ), Container( child: Text('${_dataArray[index]['createTime']}',style: TextStyle(fontSize: zsp(22),color: Color(0xFF9A9A9A)),), margin: EdgeInsets.only(top: hsp(10)), ), ], ) ], ), GestureDetector( child: Container( height: hsp(60), decoration: BoxDecoration( color: Color(0xFF007AFF), borderRadius: BorderRadius.all(Radius.circular(50)) ), alignment: Alignment.center, child: Text(_dataArray[index]['isAttention']==1?'取消关注':'关注',style: TextStyle(color: Colors.white,fontSize: zsp(24)),), padding: EdgeInsets.only(left: hsp(20),right: hsp(20)), ), onTap: (){ _postAuthorAttention(index); }, ) ], ):Column( children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( height: hsp(66), width: hsp(66), decoration: BoxDecoration( color: Colors.lightBlue, borderRadius: BorderRadius.all(Radius.circular(hsp(33))) ), margin: EdgeInsets.only(right: wsp(20)), child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(hsp(33))), child: ysImageLoad( imageUrl: '${_dataArray[index]['users']['avatar']}', fit: BoxFit.fill, height: hsp(66), width: hsp(66), ), ), ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('${_dataArray[index]['users']['nickname']}', style: TextStyle(fontSize: zsp(28),color: Color(0xFF3C61B2),fontWeight: FontWeight.bold),), Container( child: Text('${_dataArray[index]['createTime']}',style: TextStyle(fontSize: zsp(22),color: Color(0xFF9A9A9A)),), margin: EdgeInsets.only(top: hsp(10)), ), ], ) ], ), Container( child: Text('${_dataArray[index]['type']=='3'?'@我 ':''}${_dataArray[index]['content']}',style: TextStyle(fontSize: zsp(28),color: Color(0xFF343434)),), width: MediaQuery.of(context).size.width-hsp(66), margin: EdgeInsets.only(top: hsp(30),bottom: hsp(20)), ), GestureDetector( onTap: (){ Navigator.of(context,rootNavigator: true).push( CupertinoPageRoute( builder: (context){ return _dataArray[index]['squareMessage']['type']==1?YSSquareArticle(squareId: _dataArray[index] ['squareMessage']['id'],typeId: _dataArray[index]['squareMessage']['type'],) :YSSquareVideo(squareId: _dataArray[index]['squareMessage']['id'],typeId: _dataArray[index]['squareMessage']['type'],); } ) ); }, child: Row( children: [ Container( height: hsp(120), width: hsp(120), child: ysImageLoad( imageUrl: '${_dataArray[index]['squareMessage']['cover']}', fit: BoxFit.fill, height: hsp(120), width: hsp(120), ), ), Container( height: hsp(120), width: MediaQuery.of(context).size.width-hsp(186), color: Color(0xFFF4F6F8), child: Text('${_dataArray[index]['squareMessage']['title']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF7F7F7F)),maxLines: 2,overflow: TextOverflow.ellipsis,), padding: EdgeInsets.all(hsp(20)), ) ], ), ) ], ), ); }, separatorBuilder: (context,index){ return Divider(height: hsp(12),thickness: hsp(12),color: Color(0xFFF0F0F1),); }, itemCount: _dataArray.length, padding: EdgeInsets.only(top: hsp(12),bottom: hsp(43)), ), ), if(_isShow==true)Column( children: [ Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),), Container( color: Colors.white, child: ListView.separated( shrinkWrap: true, itemBuilder: (context,index){ return GestureDetector( onTap: (){ _index = index; _isShow = false; _refresh(); }, child: Container( height: hsp(105), color: Colors.white, alignment: Alignment.centerLeft, padding: EdgeInsets.only(left: wsp(50),right: wsp(50)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('${_types[index]['name']}',style: TextStyle(fontSize: zsp(28),color: Color(0xFF343434), fontWeight: index==_index?FontWeight.bold:FontWeight.normal),), Icon(Icons.check,color: index==_index?Color(0xFF007AFF):Colors.transparent,size: hsp(40),) ], ) ), ); }, separatorBuilder: (context,index){ return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),); }, itemCount: _types.length, physics: NeverScrollableScrollPhysics(), ), ), GestureDetector( onTap: (){ setState(() { _isShow = false; }); }, child: Container( height: MediaQuery.of(context).size.height-hsp(105)*_types.length-0.5*_types.length-MediaQuery.of(context).padding.top-44, width: MediaQuery.of(context).size.width, color: Colors.black54, ), ) ], ) ], ), ); } _getTypeData() async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/message/type',parameter: {},isLoading: true,refresh: _getTypeData,isToken: true); if(dict!=null){ _types = dict['data']; _types.insert(0, {'id': 0, 'name': '全部消息', 'type': 0, 'status': 1}); _refresh(); } } Future _refresh() async{ _page = 1; Map request = {}; request['pageNo'] = _page; request['pageSize'] = 10; if(_index!=0){ request['type'] = _types[_index]['type']; } Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/message',parameter: request, isLoading: true,refresh: _refresh,isToken: true); if(dict!=null){ setState(() { _dataArray = dict['data']['resultList']; }); } } Future _loadMore() async{ _page++; Map request = {}; request['pageNo'] = _page; request['pageSize'] = 10; if(_index!=0){ request['type'] = _types[_index]['type']; } Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/message',parameter: request, isLoading: true,refresh: _loadMore,isToken: true); if(dict!=null){ setState(() { _dataArray.addAll(dict['data']['resultList']); }); } } _postAuthorAttention(int index) async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/attention', parameter: {'userId':_dataArray[index]['users']['id']},isLoading: false,isToken: true,refresh: (){}); if(dict!=null){ setState(() { _dataArray[index]['isAttention'] = dict['data']; }); } } }