announ_page.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/announ_vm.dart';
  14. import '../../announcement_detail/page/announcement_detail_page.dart';
  15. @RoutePage()
  16. class AnnounPage extends HookConsumerWidget {
  17. const AnnounPage({Key? key}) : super(key: key);
  18. //启动当前页面
  19. static void startInstance({BuildContext? context}) {
  20. if (context != null) {
  21. context.router.push(const AnnounPageRoute());
  22. } else {
  23. appRouter.push(const AnnounPageRoute());
  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(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: [BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)],
  59. ),
  60. child: Column(
  61. children: [
  62. Container(
  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).marginOnly(bottom: 5),
  71. _buildItemRightSection(context, ref, item, _vm),
  72. ],
  73. ).paddingOnly(left: 20,right: 20),
  74. ).constrained(
  75. minHeight: 117.5,
  76. ),
  77. ],
  78. ).onTap(() {
  79. // 去详情
  80. // Navigator.push(
  81. // context,
  82. // MaterialPageRoute(builder: (context) => AnnouncementDetailPage()),
  83. // );
  84. AnnouncementDetailPage.startInstance(context: context);
  85. // _vm.goNewsDetail(item['title']);
  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(announVmProvider.notifier);
  102. return Scaffold(
  103. // appBar: AppBar(title: Text("资产")),
  104. body: Container(
  105. child: EasyRefresh(
  106. // 上拉加载
  107. onLoad: () async {
  108. Log.d("----onLoad");
  109. _vm.onLoadData();
  110. },
  111. // 下拉刷新
  112. onRefresh: () async {
  113. Log.d("----onRefresh");
  114. _vm.refreshListData();
  115. },
  116. child: Container(
  117. color: ColorUtils.string2Color('#F2F3F6'),
  118. padding: const EdgeInsets.only(top: 15),
  119. child: _buildSaleList(context, ref, _vm)),
  120. )),
  121. );
  122. }
  123. }