announ_page.dart 4.1 KB

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