123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- 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<YSMessage> {
- 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<void> _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<void> _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'];
- });
- }
- }
- }
|