event_page.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. // _vm.goNewsDetail(item['title']);
  84. Navigator.push(
  85. context,
  86. MaterialPageRoute(builder: (context) => const EventDetailPage()),
  87. );
  88. }),
  89. ).marginOnly(left: 15, bottom: 15, right: 15);
  90. }
  91. // list
  92. Widget _buildSaleList(BuildContext context, WidgetRef ref, _vm) {
  93. List itemsList = _vm.state.list.toList();
  94. return ListView.builder(
  95. itemCount: itemsList.length,
  96. itemBuilder: (context, index) {
  97. return _buildSaleItem(context, ref, itemsList[index], _vm);
  98. },
  99. );
  100. }
  101. @override
  102. Widget build(BuildContext context, WidgetRef ref) {
  103. final vm = ref.read(eventVmProvider.notifier);
  104. final state = ref.watch(eventVmProvider);
  105. useEffect(() {
  106. // 组件挂载时执行 - 执行接口请求
  107. Future.microtask(() => vm.initPageData());
  108. return () {
  109. // 组件卸载时执行
  110. Log.d("property_news_page 组件卸载时执行");
  111. };
  112. }, []);
  113. return Scaffold(
  114. // appBar: AppBar(title: Text("资产")),
  115. body: SizedBox(
  116. width: double.infinity,
  117. height: double.infinity,
  118. child: EasyRefresh(
  119. controller: vm.refreshController,
  120. // 上拉加载
  121. onLoad: () async {
  122. Log.d("----onLoad");
  123. vm.loadMore();
  124. },
  125. // 下拉刷新
  126. onRefresh: () async {
  127. Log.d("----onRefresh");
  128. vm.onRefresh();
  129. },
  130. child: Container(
  131. color: ColorUtils.string2Color('#F2F3F6'),
  132. padding: const EdgeInsets.only(top: 15),
  133. child: LoadStateLayout(
  134. state: state.loadingState,
  135. errorMessage: state.errorMessage,
  136. errorRetry: () {
  137. vm.retryRequest();
  138. },
  139. successSliverWidget: [_buildSaleList(context, ref, vm)],
  140. ),
  141. ))),
  142. );
  143. }
  144. }