ArticleInfo.dart 2.9KB

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