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