event_page.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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:hooks_riverpod/hooks_riverpod.dart';
  5. import 'package:router/ext/auto_router_extensions.dart';
  6. import 'package:shared/utils/log_utils.dart';
  7. import 'package:shared/utils/color_utils.dart';
  8. import 'package:widgets/ext/ex_widget.dart';
  9. import 'package:widgets/my_load_image.dart';
  10. import 'package:widgets/widget_export.dart';
  11. import 'package:cs_resources/generated/assets.dart';
  12. import '../../../router/page/notice_board_page_router.dart';
  13. import '../vm/event_vm.dart';
  14. @RoutePage()
  15. class EventPage extends HookConsumerWidget {
  16. const EventPage({Key? key}) : super(key: key);
  17. //启动当前页面
  18. static void startInstance({BuildContext? context}) {
  19. if (context != null) {
  20. context.router.push(const EventPageRoute());
  21. } else {
  22. appRouter.push(const EventPageRoute());
  23. }
  24. }
  25. Widget _buildItemLeftSection(BuildContext context, WidgetRef ref, item, _vm) {
  26. return Container(
  27. // color: Colors.blue,
  28. child: Text(
  29. maxLines: 2, // 设置最大行数为2
  30. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  31. item['title'],
  32. style: const TextStyle(
  33. fontSize: 16.0,
  34. color: Colors.black,
  35. fontWeight: FontWeight.w700), // 设置字体大小
  36. ),
  37. );
  38. }
  39. Widget _buildItemRightSection(
  40. BuildContext context, WidgetRef ref, item, _vm) {
  41. return Container(
  42. // color: Colors.green,
  43. child: Text(
  44. item['price'],
  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. Container(
  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. }),
  85. ).marginOnly(left: 15, bottom: 15, right: 15);
  86. }
  87. // list
  88. Widget _buildSaleList(BuildContext context, WidgetRef ref, _vm) {
  89. List itemsList = _vm.state.list.toList();
  90. return ListView.builder(
  91. itemCount: itemsList.length,
  92. itemBuilder: (context, index) {
  93. return _buildSaleItem(context, ref, itemsList[index], _vm);
  94. },
  95. );
  96. }
  97. @override
  98. Widget build(BuildContext context, WidgetRef ref) {
  99. final _vm = ref.read(eventVmProvider.notifier);
  100. return Scaffold(
  101. // appBar: AppBar(title: Text("资产")),
  102. body: Container(
  103. child: EasyRefresh(
  104. // 上拉加载
  105. onLoad: () async {
  106. Log.d("----onLoad");
  107. _vm.onLoadData();
  108. },
  109. // 下拉刷新
  110. onRefresh: () async {
  111. Log.d("----onRefresh");
  112. _vm.refreshListData();
  113. },
  114. child: Container(
  115. color: ColorUtils.string2Color('#F2F3F6'),
  116. padding: const EdgeInsets.only(top: 15),
  117. child: _buildSaleList(context, ref, _vm)),
  118. )),
  119. );
  120. }
  121. }