ArticleInfo.dart 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import 'package:farmer_client/services/news.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_easyloading/flutter_easyloading.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:get/get.dart';
  6. import 'package:get/get_core/src/get_main.dart';
  7. import '../../models/entities/NewsInformationInfoTextModel.dart';
  8. import '../../models/entities/NewsInformationModel.dart';
  9. import '../../widgets/layout/BasicPage.dart';
  10. class ArticleInfo extends BasicPage {
  11. String newsId = '';
  12. final newsInfoContent =
  13. Rx<NewsInformationInfoTextModel>(NewsInformationInfoTextModel());
  14. final newsList = Rx<List<ExtendContent>>([]);
  15. @override
  16. void beforeShow() {
  17. // TODO: implement beforeShow
  18. super.beforeShow();
  19. if (Get.arguments['newsId'] != null) {
  20. EasyLoading.show(status: '数据加载中...');
  21. newsId = Get.arguments['newsId'];
  22. getNewsInfo(newsId).then((value) {
  23. newsInfoContent.value = NewsInformationInfoTextModel.fromJson(value);
  24. newsList.value = newsInfoContent.value.contentList!;
  25. EasyLoading.dismiss();
  26. });
  27. }
  28. }
  29. @override
  30. Widget builder(BuildContext context) {
  31. naviTitle = '资讯详情';
  32. return Container(
  33. padding: EdgeInsets.fromLTRB(15, 30, 15, 0),
  34. child: ListView(
  35. children: [
  36. Container(
  37. child: Row(
  38. mainAxisAlignment: MainAxisAlignment.center,
  39. children: [
  40. Image(
  41. image: AssetImage('images/icons/decorate.png'),
  42. width: 17,
  43. ),
  44. Container(
  45. alignment: Alignment.center,
  46. width: 260.w,
  47. child: Obx(() => Text(
  48. newsInfoContent.value.title.toString(),
  49. style: TextStyle(
  50. fontSize: 17.sp,
  51. fontWeight: FontWeight.bold,
  52. ),
  53. )),
  54. ),
  55. Image(
  56. image: AssetImage('images/icons/decorate.png'), width: 17),
  57. ],
  58. ),
  59. ),
  60. Obx(() => Column(
  61. children: newsList.value.map((item) {
  62. if (item.contentType != 'image') {
  63. return Container(
  64. padding: EdgeInsets.fromLTRB(0, 20, 0, 10),
  65. width: 344.w,
  66. child: Text(
  67. item.content.toString(),
  68. style: TextStyle(fontSize: 14.sp),
  69. ),
  70. );
  71. } else {
  72. return Container(
  73. padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
  74. child: Image(
  75. image: NetworkImage(item.content.toString()),
  76. width: 320.w,
  77. height: 260.w,
  78. fit: BoxFit.fill,
  79. ),
  80. );
  81. }
  82. }).toList(),
  83. )),
  84. ],
  85. ),
  86. );
  87. }
  88. }