announ_page.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import 'package:cpt_notice_board/modules/notice_board/page/notice_board_page.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:auto_route/auto_route.dart';
  4. import 'package:flutter_hooks/flutter_hooks.dart';
  5. import 'package:hooks_riverpod/hooks_riverpod.dart';
  6. import 'package:router/ext/auto_router_extensions.dart';
  7. import 'package:shared/utils/log_utils.dart';
  8. import 'package:shared/utils/color_utils.dart';
  9. import 'package:widgets/ext/ex_widget.dart';
  10. import 'package:widgets/load_state_layout.dart';
  11. import 'package:widgets/my_load_image.dart';
  12. import 'package:widgets/widget_export.dart';
  13. import 'package:cs_resources/generated/assets.dart';
  14. import '../../../router/page/notice_board_page_router.dart';
  15. import '../vm/announ_vm.dart';
  16. import '../../announcement_detail/page/announcement_detail_page.dart';
  17. @RoutePage()
  18. class AnnounPage extends HookConsumerWidget {
  19. const AnnounPage({Key? key}) : super(key: key);
  20. //启动当前页面
  21. static void startInstance({BuildContext? context}) {
  22. if (context != null) {
  23. context.router.push(const AnnounPageRoute());
  24. } else {
  25. appRouter.push(const AnnounPageRoute());
  26. }
  27. }
  28. Widget _buildItemLeftSection(BuildContext context, WidgetRef ref, item, vm) {
  29. return Container(
  30. // color: Colors.blue,
  31. child: Text(
  32. maxLines: 2, // 设置最大行数为2
  33. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  34. item['title'],
  35. style: const TextStyle(
  36. fontSize: 16.0,
  37. color: Colors.black,
  38. fontWeight: FontWeight.w700), // 设置字体大小
  39. ),
  40. );
  41. }
  42. Widget _buildItemRightSection(BuildContext context, WidgetRef ref, item, vm) {
  43. return Container(
  44. // color: Colors.green,
  45. child: Text(
  46. item['created_at'],
  47. style: const TextStyle(
  48. fontSize: 14.0,
  49. color: Colors.black,
  50. fontWeight: FontWeight.w400), // 设置字体大小
  51. ),
  52. );
  53. }
  54. // listitem
  55. Widget _buildSaleItem(BuildContext context, WidgetRef ref, item, vm) {
  56. return Container(
  57. decoration: const BoxDecoration(
  58. color: Colors.white,
  59. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  60. boxShadow: [
  61. BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
  62. ],
  63. ),
  64. child: Column(
  65. children: [
  66. Container(
  67. width: MediaQuery.of(context).size.width - 30,
  68. height: 100,
  69. // margin: const EdgeInsets.only(left: 15, right: 15, top: 12.5),
  70. child: Column(
  71. crossAxisAlignment: CrossAxisAlignment.start,
  72. mainAxisAlignment: MainAxisAlignment.center,
  73. children: [
  74. _buildItemLeftSection(context, ref, item, vm)
  75. .marginOnly(bottom: 5),
  76. _buildItemRightSection(context, ref, item, vm),
  77. ],
  78. ).paddingOnly(left: 20, right: 20),
  79. ).constrained(
  80. minHeight: 117.5,
  81. ),
  82. ],
  83. ).onTap(() {
  84. // 去详情
  85. // AnnouncementDetailPage.startInstance(context: context);
  86. AnnouncementDetailPage.startInstance(id: item['id']);
  87. }),
  88. ).marginOnly(left: 15, bottom: 15, right: 15);
  89. }
  90. // list
  91. Widget _buildSaleList(BuildContext context, WidgetRef ref, vm) {
  92. final state = ref.watch(announVmProvider);
  93. return SliverList(
  94. delegate: SliverChildBuilderDelegate((context, index) {
  95. return _buildSaleItem(context, ref, state.list![index], vm);
  96. }, childCount: state.list!.length));
  97. }
  98. @override
  99. Widget build(BuildContext context, WidgetRef ref) {
  100. final vm = ref.read(announVmProvider.notifier);
  101. final state = ref.watch(announVmProvider);
  102. useEffect(() {
  103. // 组件挂载时执行 - 执行接口请求
  104. Future.microtask(() => vm.initPageData());
  105. return () {
  106. // 组件卸载时执行
  107. Log.d("property_news_page 组件卸载时执行");
  108. };
  109. }, []);
  110. return Scaffold(
  111. // appBar: AppBar(title: Text("资产")),
  112. body: SizedBox(
  113. width: double.infinity,
  114. height: double.infinity,
  115. child: EasyRefresh(
  116. controller: vm.refreshController,
  117. // 上拉加载
  118. onLoad: () async {
  119. Log.d("----onLoad");
  120. vm.loadMore();
  121. },
  122. // 下拉刷新
  123. onRefresh: () async {
  124. Log.d("----onRefresh");
  125. vm.onRefresh();
  126. },
  127. child: Container(
  128. color: ColorUtils.string2Color('#F2F3F6'),
  129. padding: const EdgeInsets.only(top: 15),
  130. child: LoadStateLayout(
  131. state: state.loadingState,
  132. errorMessage: state.errorMessage,
  133. errorRetry: () {
  134. vm.retryRequest();
  135. },
  136. successSliverWidget: [_buildSaleList(context, ref, vm)],
  137. ),
  138. ))),
  139. );
  140. }
  141. }