YSNewDetail.dart 5.2 KB

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