ArticleInfo.dart 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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, 50),
  34. child: Column(
  35. children: [
  36. Container(
  37. alignment: Alignment.center,
  38. child: Row(
  39. mainAxisAlignment: MainAxisAlignment.center,
  40. children: [
  41. Image(
  42. image: AssetImage('images/icons/decorate.png'),
  43. width: 17,
  44. ),
  45. Obx(() => Text(
  46. newsInfoContent.value.title.toString(),
  47. style: TextStyle(
  48. fontSize: 17.sp,
  49. fontWeight: FontWeight.bold,
  50. ),
  51. )),
  52. Image(
  53. image: AssetImage('images/icons/decorate.png'), width: 17),
  54. ],
  55. ),
  56. ),
  57. Obx(() => Column(
  58. children: newsList.value.map((item) {
  59. if (item.contentType != 'image') {
  60. return Container(
  61. padding: EdgeInsets.fromLTRB(0, 20, 0, 10),
  62. width: 344.w,
  63. child: Text(
  64. item.content.toString(),
  65. style: TextStyle(fontSize: 14.sp),
  66. ),
  67. );
  68. } else {
  69. return Container(
  70. padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
  71. child: Image(
  72. image: NetworkImage(item.content.toString()),
  73. width: 320.w,
  74. height: 260.w,
  75. fit: BoxFit.fill,
  76. ),
  77. );
  78. }
  79. }).toList(),
  80. )),
  81. ],
  82. ),
  83. );
  84. }
  85. }