import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:ysairplane/base/YSBase.dart'; import 'package:ysairplane/tools/YSNetWorking.dart'; import 'package:ysairplane/tools/YSTools.dart'; class YSNewDetail extends StatefulWidget { final String newId; const YSNewDetail({Key key, this.newId}) : super(key: key); @override _YSNewDetailState createState() => _YSNewDetailState(); } class _YSNewDetailState extends State { Map _dict; int _like = 0; @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _getNewsDetailData(); }); super.initState(); } @override Widget build(BuildContext context) { return YSBase( ystitle: '详情', yschild: _dict==null?Container():Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44-hsp(160), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( padding: EdgeInsets.all(hsp(40)), child: Text('${_dict['title']}',style: TextStyle(color: Color(0xFF333333),fontSize: zsp(36),fontWeight: FontWeight.bold),), ), Container( padding: EdgeInsets.only(top: hsp(10),left: hsp(40),right: hsp(40),bottom: hsp(40)), child: Text('${_dict['createtime']} ${_dict['author']}',style: TextStyle(color: Color(0xFF999999),fontSize: zsp(24)),), ), Container( padding: EdgeInsets.only(left: hsp(40),right: hsp(40),bottom: hsp(40)), child: Text('${_dict['content']}',style: TextStyle(color: Color(0xFF333333),fontSize: zsp(30),),) ) ], ), ), ), Container( height: hsp(160), padding: EdgeInsets.all(hsp(30)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ GestureDetector( onTap: (){ _postLikeData(); }, child: Container( width: (MediaQuery.of(context).size.width-wsp(100))/2, height: hsp(83), color: Color(0xFFF8F8F8), alignment: Alignment.center, child: Row( mainAxisSize: MainAxisSize.min, children: [ Image(image: AssetImage('lib/images/agree.png'),height: hsp(50),width: hsp(50),color: _like==0?Color(0xFF636363):Colors.pinkAccent), Text(' ${_dict['likeCount']}',style: TextStyle(fontSize: zsp(28),color: _like==0?Color(0xFF636363):Colors.pinkAccent),) ], ), ), ), Container( width: (MediaQuery.of(context).size.width-wsp(100))/2, height: hsp(83), color: Color(0xFFF8F8F8), alignment: Alignment.center, child: Row( mainAxisSize: MainAxisSize.min, children: [ Image(image: AssetImage('lib/images/wechat.png'),height: hsp(50),width: hsp(50),), Text(' 微信好友',style: TextStyle(fontSize: zsp(28),color: Color(0xFF636363)),) ], ), ) ], ), ) ], ), ); } _getNewsDetailData() async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/details',parameter: {'id':widget.newId},isLoading: true,isToken: true); if(dict!=null){ setState(() { _dict = dict['data']; _like = _dict['isLike']; }); } } _postLikeData() async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/like',parameter: {'headlineId':widget.newId},isLoading: false,isToken: true); if(dict!=null){ setState(() { _like = dict['data']; _dict['likeCount'] = int.parse('${_dict['likeCount']}')+(_like==0?-1:1); }); } } }