event_page.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 Container(
  28. // color: Colors.blue,
  29. child: 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. }
  40. Widget _buildItemRightSection(
  41. BuildContext context, WidgetRef ref, item, _vm) {
  42. return Container(
  43. // color: Colors.green,
  44. child: Text(
  45. item['price'],
  46. style: const TextStyle(
  47. fontSize: 14.0,
  48. color: Colors.black,
  49. fontWeight: FontWeight.w400), // 设置字体大小
  50. ),
  51. );
  52. }
  53. // listitem
  54. Widget _buildSaleItem(BuildContext context, WidgetRef ref, item, _vm) {
  55. return Container(
  56. decoration: const BoxDecoration(
  57. color: Colors.white,
  58. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  59. boxShadow: [
  60. BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
  61. ],
  62. ),
  63. child: Column(
  64. children: [
  65. Container(
  66. width: MediaQuery.of(context).size.width - 30,
  67. height: 100,
  68. // margin: const EdgeInsets.only(left: 15, right: 15, top: 12.5),
  69. child: Column(
  70. crossAxisAlignment: CrossAxisAlignment.start,
  71. mainAxisAlignment: MainAxisAlignment.center,
  72. children: [
  73. _buildItemLeftSection(context, ref, item, _vm)
  74. .marginOnly(bottom: 5),
  75. _buildItemRightSection(context, ref, item, _vm),
  76. ],
  77. ).paddingOnly(left: 20, right: 20),
  78. ).constrained(
  79. minHeight: 117.5,
  80. ),
  81. ],
  82. ).onTap(() {
  83. // 去详情
  84. // _vm.goNewsDetail(item['title']);
  85. Navigator.push(
  86. context,
  87. MaterialPageRoute(builder: (context) => const EventDetailPage()),
  88. );
  89. }),
  90. ).marginOnly(left: 15, bottom: 15, right: 15);
  91. }
  92. // list
  93. Widget _buildSaleList(BuildContext context, WidgetRef ref, _vm) {
  94. List itemsList = _vm.state.list.toList();
  95. return ListView.builder(
  96. itemCount: itemsList.length,
  97. itemBuilder: (context, index) {
  98. return _buildSaleItem(context, ref, itemsList[index], _vm);
  99. },
  100. );
  101. }
  102. @override
  103. Widget build(BuildContext context, WidgetRef ref) {
  104. final _vm = ref.read(eventVmProvider.notifier);
  105. return Scaffold(
  106. // appBar: AppBar(title: Text("资产")),
  107. body: Container(
  108. child: EasyRefresh(
  109. // 上拉加载
  110. onLoad: () async {
  111. Log.d("----onLoad");
  112. _vm.onLoadData();
  113. },
  114. // 下拉刷新
  115. onRefresh: () async {
  116. Log.d("----onRefresh");
  117. _vm.refreshListData();
  118. },
  119. child: Container(
  120. color: ColorUtils.string2Color('#F2F3F6'),
  121. padding: const EdgeInsets.only(top: 15),
  122. child: _buildSaleList(context, ref, _vm)),
  123. )),
  124. );
  125. }
  126. }