event_page.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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: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/my_load_image.dart';
  11. import 'package:widgets/widget_export.dart';
  12. import 'package:cs_resources/generated/assets.dart';
  13. import '../../../router/page/notice_board_page_router.dart';
  14. import '../vm/event_vm.dart';
  15. @RoutePage()
  16. class EventPage extends HookConsumerWidget {
  17. const EventPage({Key? key}) : super(key: key);
  18. //启动当前页面
  19. static void startInstance({BuildContext? context}) {
  20. if (context != null) {
  21. context.router.push(const EventPageRoute());
  22. } else {
  23. appRouter.push(const EventPageRoute());
  24. }
  25. }
  26. Widget _buildItemLeftSection(BuildContext context, WidgetRef ref, item, _vm) {
  27. return Text(
  28. maxLines: 2, // 设置最大行数为2
  29. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  30. item['title'],
  31. style: const TextStyle(
  32. fontSize: 16.0,
  33. color: Colors.black,
  34. fontWeight: FontWeight.w700), // 设置字体大小
  35. );
  36. }
  37. Widget _buildItemRightSection(
  38. BuildContext context, WidgetRef ref, item, _vm) {
  39. return Container(
  40. // color: Colors.green,
  41. child: Text(
  42. item['price'],
  43. style: const TextStyle(
  44. fontSize: 14.0,
  45. color: Colors.black,
  46. fontWeight: FontWeight.w400), // 设置字体大小
  47. ),
  48. );
  49. }
  50. // listitem
  51. Widget _buildSaleItem(BuildContext context, WidgetRef ref, item, _vm) {
  52. return Container(
  53. decoration: const BoxDecoration(
  54. color: Colors.white,
  55. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  56. boxShadow: [
  57. BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
  58. ],
  59. ),
  60. child: Column(
  61. children: [
  62. SizedBox(
  63. width: MediaQuery.of(context).size.width - 30,
  64. height: 100,
  65. // margin: const EdgeInsets.only(left: 15, right: 15, top: 12.5),
  66. child: Column(
  67. crossAxisAlignment: CrossAxisAlignment.start,
  68. mainAxisAlignment: MainAxisAlignment.center,
  69. children: [
  70. _buildItemLeftSection(context, ref, item, _vm)
  71. .marginOnly(bottom: 5),
  72. _buildItemRightSection(context, ref, item, _vm),
  73. ],
  74. ).paddingOnly(left: 20, right: 20),
  75. ).constrained(
  76. minHeight: 117.5,
  77. ),
  78. ],
  79. ).onTap(() {
  80. // 去详情
  81. // _vm.goNewsDetail(item['title']);
  82. Navigator.push(
  83. context,
  84. MaterialPageRoute(builder: (context) => const EventDetailPage()),
  85. );
  86. }),
  87. ).marginOnly(left: 15, bottom: 15, right: 15);
  88. }
  89. // list
  90. Widget _buildSaleList(BuildContext context, WidgetRef ref, _vm) {
  91. List itemsList = _vm.state.list.toList();
  92. return ListView.builder(
  93. itemCount: itemsList.length,
  94. itemBuilder: (context, index) {
  95. return _buildSaleItem(context, ref, itemsList[index], _vm);
  96. },
  97. );
  98. }
  99. @override
  100. Widget build(BuildContext context, WidgetRef ref) {
  101. final _vm = ref.read(eventVmProvider.notifier);
  102. return Scaffold(
  103. // appBar: AppBar(title: Text("资产")),
  104. body: EasyRefresh(
  105. // 上拉加载
  106. onLoad: () async {
  107. Log.d("----onLoad");
  108. _vm.onLoadData();
  109. },
  110. // 下拉刷新
  111. onRefresh: () async {
  112. Log.d("----onRefresh");
  113. _vm.refreshListData();
  114. },
  115. child: Container(
  116. color: ColorUtils.string2Color('#F2F3F6'),
  117. padding: const EdgeInsets.only(top: 15),
  118. child: _buildSaleList(context, ref, _vm)),
  119. ),
  120. );
  121. }
  122. }