event_page.dart 5.0 KB

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