YSNewDetail.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:ysairplane/base/YSBase.dart';
  4. import 'package:ysairplane/tools/YSNetWorking.dart';
  5. import 'package:ysairplane/tools/YSTools.dart';
  6. class YSNewDetail extends StatefulWidget {
  7. final String newId;
  8. const YSNewDetail({Key key, this.newId}) : super(key: key);
  9. @override
  10. _YSNewDetailState createState() => _YSNewDetailState();
  11. }
  12. class _YSNewDetailState extends State<YSNewDetail> {
  13. Map _dict;
  14. int _like = 0;
  15. @override
  16. void initState() {
  17. Future.delayed(Duration(seconds: 0)).then((value){
  18. _getNewsDetailData();
  19. });
  20. super.initState();
  21. }
  22. @override
  23. Widget build(BuildContext context) {
  24. return YSBase(
  25. ystitle: '详情',
  26. yschild: _dict==null?Container():Column(
  27. crossAxisAlignment: CrossAxisAlignment.start,
  28. children: [
  29. Container(
  30. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44-hsp(160),
  31. child: SingleChildScrollView(
  32. child: Column(
  33. crossAxisAlignment: CrossAxisAlignment.start,
  34. children: [
  35. Container(
  36. padding: EdgeInsets.all(hsp(40)),
  37. child: Text('${_dict['title']}',style: TextStyle(color: Color(0xFF333333),fontSize: zsp(36),fontWeight: FontWeight.bold),),
  38. ),
  39. Container(
  40. padding: EdgeInsets.only(top: hsp(10),left: hsp(40),right: hsp(40),bottom: hsp(40)),
  41. child: Text('${_dict['createtime']} ${_dict['author']}',style: TextStyle(color: Color(0xFF999999),fontSize: zsp(24)),),
  42. ),
  43. Container(
  44. padding: EdgeInsets.only(left: hsp(40),right: hsp(40),bottom: hsp(40)),
  45. child: Text('${_dict['content']}',style: TextStyle(color: Color(0xFF333333),fontSize: zsp(30),),)
  46. )
  47. ],
  48. ),
  49. ),
  50. ),
  51. Container(
  52. height: hsp(160),
  53. padding: EdgeInsets.all(hsp(30)),
  54. child: Row(
  55. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  56. children: [
  57. GestureDetector(
  58. onTap: (){
  59. _postLikeData();
  60. },
  61. child: Container(
  62. width: (MediaQuery.of(context).size.width-wsp(100))/2,
  63. height: hsp(83),
  64. color: Color(0xFFF8F8F8),
  65. alignment: Alignment.center,
  66. child: Row(
  67. mainAxisSize: MainAxisSize.min,
  68. children: [
  69. Image(image: AssetImage('lib/images/agree.png'),height: hsp(50),width: hsp(50),color: _like==0?Color(0xFF636363):Colors.pinkAccent),
  70. Text(' ${_dict['likeCount']}',style: TextStyle(fontSize: zsp(28),color: _like==0?Color(0xFF636363):Colors.pinkAccent),)
  71. ],
  72. ),
  73. ),
  74. ),
  75. Container(
  76. width: (MediaQuery.of(context).size.width-wsp(100))/2,
  77. height: hsp(83),
  78. color: Color(0xFFF8F8F8),
  79. alignment: Alignment.center,
  80. child: Row(
  81. mainAxisSize: MainAxisSize.min,
  82. children: [
  83. Image(image: AssetImage('lib/images/wechat.png'),height: hsp(50),width: hsp(50),),
  84. Text(' 微信好友',style: TextStyle(fontSize: zsp(28),color: Color(0xFF636363)),)
  85. ],
  86. ),
  87. )
  88. ],
  89. ),
  90. )
  91. ],
  92. ),
  93. );
  94. }
  95. _getNewsDetailData() async{
  96. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/details',parameter: {'id':widget.newId},isLoading: true,isToken: true);
  97. if(dict!=null){
  98. setState(() {
  99. _dict = dict['data'];
  100. _like = _dict['isLike'];
  101. });
  102. }
  103. }
  104. _postLikeData() async{
  105. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/headline/like',parameter: {'headlineId':widget.newId},isLoading: false,isToken: true);
  106. if(dict!=null){
  107. setState(() {
  108. _like = dict['data'];
  109. _dict['likeCount'] = int.parse('${_dict['likeCount']}')+(_like==0?-1:1);
  110. });
  111. }
  112. }
  113. }