import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:ysairplane/tools/YSNetWorking.dart'; import 'package:ysairplane/tools/YSTools.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'YSSquareArticle.dart'; import 'YSSquareVideo.dart'; class YSAuthorSquare extends StatefulWidget { final int authorId; const YSAuthorSquare({Key key, this.authorId}) : super(key: key); @override _YSAuthorSquareState createState() => _YSAuthorSquareState(); } class _YSAuthorSquareState extends State { ScrollController _scrollController = ScrollController(); Map _dict; int _selected = 0; List _dataArray = []; int _page = 1; int _isAttention = 0; @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _getUserInfoData(); }); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, body: EasyRefresh( onRefresh: _refresh, onLoad: _loadMore, header: MaterialHeader( ), footer: BezierBounceFooter( backgroundColor: Colors.transparent, color: Colors.transparent, ), child: SingleChildScrollView( child: Stack( children: [ Container( height: hsp(300)+MediaQuery.of(context).padding.top, width: MediaQuery.of(context).size.width, child: Image( image: _dict==null?AssetImage('lib/images/squareBg2.png'):NetworkImage('${_dict['backGroundUrl']}'), fit: BoxFit.fill, ), ), Container( margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+10,left: 15,right: 15), height: 50, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ GestureDetector( child: Icon(Icons.arrow_back_ios,size: 20,color: Colors.white,), onTap: (){ Navigator.pop(context); }, ), ], ), ), Container( height: hsp(160), width: hsp(160), margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(220),left: wsp(40)), decoration: BoxDecoration( image: DecorationImage(image: _dict==null?AssetImage('lib/images/head.png'):NetworkImage('${_dict['user']['avatar']}')), borderRadius: BorderRadius.all(Radius.circular(35)) ), ), GestureDetector( onTap: (){ _postAuthorAttention(); }, child: Container( height: hsp(60), width: wsp(160), margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(314),left: MediaQuery.of(context).size.width-wsp(200)), decoration: BoxDecoration( color: _isAttention==0?Color(0xFFED4946):Color(0xFFBCBCBC), borderRadius: BorderRadius.all(Radius.circular(3)) ), alignment: Alignment.center, child: Text(_isAttention==0?'+ 关注':'取消关注',style: TextStyle(color: Colors.white,fontSize: zsp(24)),), ), ), Container( margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(400)), width: MediaQuery.of(context).size.width, child: Column( children: [ Container( child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( child: Row( children: [ Text(_dict==null?'':(_dict['user']['nickname']).toString().length>10?(_dict['user']['nickname']).toString().substring(0,10)+'..':(_dict['user']['nickname']).toString(), style: TextStyle(fontSize: 16,color: Color(0xFF333333),fontWeight: FontWeight.bold,decoration: TextDecoration.none),maxLines: 1,overflow: TextOverflow.ellipsis,), Icon(Icons.pregnant_woman,color: Colors.pinkAccent,), ], ), ), Container( child: Text(_dict==null?'':'${_dict['labelIds']}', style: TextStyle(fontSize: 12,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none),), margin: EdgeInsets.only(top: hsp(20),bottom: hsp(20)), ), Row( children: [ Container( child: Text('陕西西安', style: TextStyle(fontSize: 10,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none), ), decoration: BoxDecoration( color: Color(0xFFEEEEEE), borderRadius: BorderRadius.all(Radius.circular(5)) ), padding: EdgeInsets.all(5), margin: EdgeInsets.only(bottom: hsp(20)), ), Container( child: Text(_dict==null?'':'${_dict['user']['school']}', style: TextStyle(fontSize: 10,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none), ), decoration: BoxDecoration( color: Color(0xFFEEEEEE), borderRadius: BorderRadius.all(Radius.circular(5)) ), padding: EdgeInsets.all(5), margin: EdgeInsets.only(left: 5,bottom: hsp(20)), ), ], ), Row( children: [ Column( children: [ Text(_dict==null?'':'${_dict['attention']}', style: TextStyle(fontSize: 14,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none), ), Text('关注', style: TextStyle(fontSize: 12,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none), ) ], ), Container( margin: EdgeInsets.only(left: wsp(50),right: wsp(50)), child: Column( children: [ Text(_dict==null?'':'${_dict['fans']}', style: TextStyle(fontSize: 14,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none), ), Text('粉丝', style: TextStyle(fontSize: 12,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none), ) ], ), ), Column( children: [ Text(_dict==null?'':'${_dict['likeCount']}', style: TextStyle(fontSize: 14,color: Color(0xFF333333),fontWeight: FontWeight.normal,decoration: TextDecoration.none), ), Text('喜欢', style: TextStyle(fontSize: 12,color: Color(0xFF666666),fontWeight: FontWeight.normal,decoration: TextDecoration.none), ) ], ) ], ), ], ), padding: EdgeInsets.only(left: wsp(50),right: wsp(50),bottom: hsp(10)), ), Divider(color: Color(0xFFF4F4F4),height: hsp(40),thickness: hsp(10),), Container( width: MediaQuery.of(context).size.width, height: hsp(77), color: Colors.white, padding: EdgeInsets.only(left: 20,right: 20), child: ListView.separated( scrollDirection: Axis.horizontal, itemBuilder: (context,index){ return GestureDetector( onTap: (){ _selected = index; _refresh(); }, child: Container( height: hsp(70), width: (MediaQuery.of(context).size.width-80)/3, child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(index==0?'作品':index==1?'关注':'收藏',style: TextStyle(fontSize: 16,color: index==_selected?Color(0xFF333333):Color(0xFF666666),decoration: TextDecoration.none, fontWeight: index==_selected?FontWeight.bold:FontWeight.normal),), Container(height: 2,width: wsp(30),color: index==_selected?Color(0xFF333333):Colors.transparent,) ], ), ), ); }, separatorBuilder: (context,index){ return Container(width: 20,); }, itemCount: 3 ), ), Divider(color: Color(0xFFF4F4F4),height: hsp(2),thickness: hsp(2),), Container( margin: EdgeInsets.only(left: 10,right: 10), child: StaggeredGridView.countBuilder( shrinkWrap: true, controller: _scrollController, crossAxisCount: 4, crossAxisSpacing: 8, mainAxisSpacing: 8, itemCount: _dataArray.length, itemBuilder: (context, index) { return GestureDetector( onTap: (){ Navigator.of(context,rootNavigator: true).push( CupertinoPageRoute( builder: (context){ return _dataArray[index]['type']==1?YSSquareArticle(squareId: _dataArray[index]['id'],typeId: _dataArray[index]['type'],) :YSSquareVideo(squareId: _dataArray[index]['id'],typeId: _dataArray[index]['type'],); } ) ); }, child: Stack( children: [ Container( color: Colors.white, child:Column( children: [ AspectRatio( child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)), ), child: ClipRRect( borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)), child: CachedNetworkImage( imageUrl: _dataArray[index]['type']==0?'${_dataArray[index]['coverPath']}':'${_dataArray[index]['topicCover']}', fit: BoxFit.fill ), ), ), aspectRatio: double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}') ), Container( child: Text(_dataArray[index]['type']==0?'${_dataArray[index]['videoTitle']}':'${_dataArray[index]['topicTitle']}', style: TextStyle(fontSize: 13,color: Color(0xFF333333),decoration: TextDecoration.none,),maxLines: 2,overflow: TextOverflow.ellipsis,), padding: EdgeInsets.all(5), alignment: Alignment.centerLeft, ), Container( child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Container( height: 20, width: 20, margin: EdgeInsets.only(right: 5), decoration: BoxDecoration( color: Colors.black12, borderRadius: BorderRadius.all(Radius.circular(10)), ), child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(10)), child: CachedNetworkImage( imageUrl: '${_dataArray[index]['user']['avatar']}', fit: BoxFit.fill, ), ), ), Container( width: 70, child: Text('${_dataArray[index]['user']['nickname']}', style: TextStyle(fontSize: 12,color: Color(0xFF333333),decoration: TextDecoration.none,),overflow: TextOverflow.ellipsis,), ) ], ), GestureDetector( behavior: HitTestBehavior.opaque, child: Row( children: [ Container( height: 15, width: 15, margin: EdgeInsets.only(right: 5), child: Image.asset(_dataArray[index]['likeStatus']==0?'lib/images/love.png':'lib/images/love2.png') ), Container( child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Color(0xFFEE564C),decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,), ) ], mainAxisSize: MainAxisSize.min, ), onTap: (){ _postAgreementData(index); }, ), ], ), padding: EdgeInsets.only(left: 5,right: 5,top: 3,bottom: 5), ), ], ), ), Container( height: 15, margin: EdgeInsets.only(top: 10,left: 10), decoration: BoxDecoration( color: Colors.black12, borderRadius: BorderRadius.all(Radius.circular(7.5)), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Container( height: 10, width: 15, margin: EdgeInsets.only(right: 3), child: Image.asset('lib/images/eyes2.png') ), Container( child: Text('${_dataArray[index]['likeCounts']}',style: TextStyle(fontSize: 12,color: Colors.white,decoration: TextDecoration.none,fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,), ) ], ), padding: EdgeInsets.only(left: 8,right: 8), ), _dataArray[index]['type']==0?Container( margin: EdgeInsets.only(left: (MediaQuery.of(context).size.width-25)/2-30, top: (MediaQuery.of(context).size.width-25)/2/(double.parse('${_dataArray[index]['coverWidth']}')/double.parse('${_dataArray[index]['coverHeight']}'))-30), height: 20, width: 20, child: Icon(Icons.play_circle_filled,color: Colors.white,), ):Container() ], ), ); }, staggeredTileBuilder: (index) =>StaggeredTile.fit(2), padding: EdgeInsets.only(top: 10), ), ) ], ), ) ], ), ), ), ); } _getUserInfoData() async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/community',parameter: {'userId':widget.authorId},isLoading: true,isToken: true); if(dict!=null){ _refresh(); setState(() { _dict = dict['data']; _isAttention = _dict['isAttention']; }); } } Future _refresh() async{ _page = 1; Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/look',parameter: {'pageNo':_page,'pageSize':10,'type':_selected,'userId':widget.authorId},isLoading: false,isToken: true); if(dict!=null){ setState(() { _dataArray = dict['data']['resultList']; }); } } Future _loadMore() async{ _page++; Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/look',parameter: {'pageNo':_page,'pageSize':10,'type':_selected,'userId':widget.authorId},isLoading: false,isToken: true); if(dict!=null){ setState(() { _dataArray.addAll(dict['data']['resultList']); }); } } _postAgreementData(int index) async{ Map request = {'type':1}; if(_dataArray[index]['type']==0){ request['squareId'] = _dataArray[index]['id']; }else{ request['topicId'] = _dataArray[index]['id']; } Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/piazza/SquareCommunity/likeAndCollect',parameter: request,isLoading: false,isToken: true,refresh: (){ }); if(dict!=null){ setState(() { _dataArray[index]['likeStatus'] = dict['data']; if(dict['data'] == 0){ _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') - 1; }else{ _dataArray[index]['likeCounts'] = int.parse('${_dataArray[index]['likeCounts']}') + 1; } }); } } _postAuthorAttention() async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/piazza/SquareCommunity/attention', parameter: {'userId':widget.authorId},isLoading: false,isToken: true,refresh: _postAuthorAttention); if(dict!=null){ setState(() { _isAttention = dict['data']; }); } } }