ArticleInfo.dart 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.all(15.w),
  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. fit: BoxFit.fill,
  78. ),
  79. );
  80. }
  81. }).toList(),
  82. )),
  83. ],
  84. ),
  85. );
  86. }
  87. }