documents_page.dart 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/documents_vm.dart';
  14. @RoutePage()
  15. class DocumentsPage extends HookConsumerWidget {
  16. const DocumentsPage({Key? key}) : super(key: key);
  17. //启动当前页面
  18. static void startInstance({BuildContext? context}) {
  19. if (context != null) {
  20. context.router.push(const DocumentsPageRoute());
  21. } else {
  22. appRouter.push(const DocumentsPageRoute());
  23. }
  24. }
  25. Widget _buildItemLeftSection(BuildContext context, WidgetRef ref, item, _vm) {
  26. return Container(
  27. // color: Colors.blue,
  28. child: Text(
  29. item['title'],
  30. maxLines: 1, // 设置最大行数为2
  31. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  32. style: const TextStyle(
  33. fontSize: 16.0,
  34. color: Colors.black,
  35. fontWeight: FontWeight.w700), // 设置字体大小
  36. ),
  37. ).marginOnly(right: 17.5);
  38. }
  39. Widget _buildItemRightSection(
  40. BuildContext context, WidgetRef ref, item, _vm) {
  41. return Container(
  42. color: Colors.white,
  43. child: TextButton(
  44. onPressed: () {},
  45. style: TextButton.styleFrom(
  46. foregroundColor: Colors.black,
  47. backgroundColor: ColorUtils.string2Color('#4161D0'), // 背景颜色
  48. minimumSize: const Size(91.5, 30), // 最小宽度和高度
  49. padding:
  50. const EdgeInsets.symmetric(horizontal: 11.0, vertical: 9), // 内边距
  51. shape: RoundedRectangleBorder(
  52. borderRadius: BorderRadius.circular(5), // 圆角
  53. side: BorderSide(
  54. color: ColorUtils.string2Color('#4161D0'),
  55. width: 1.0,
  56. ), // 边框
  57. ),
  58. ),
  59. child: const Text('Open Folder',
  60. style: const TextStyle(color: Colors.white,),
  61. ),
  62. ),
  63. );
  64. }
  65. // listitem
  66. Widget _buildSaleItem(BuildContext context, WidgetRef ref, item, _vm) {
  67. return Container(
  68. decoration: const BoxDecoration(
  69. color: Colors.white,
  70. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  71. boxShadow: [
  72. BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
  73. ],
  74. ),
  75. child: Row(
  76. mainAxisAlignment: MainAxisAlignment.center,
  77. crossAxisAlignment: CrossAxisAlignment.center,
  78. mainAxisSize: MainAxisSize.max,
  79. children: [
  80. Container(
  81. width: MediaQuery.of(context).size.width - 30,
  82. height: 70,
  83. child: Row(
  84. mainAxisAlignment: MainAxisAlignment.start,
  85. crossAxisAlignment: CrossAxisAlignment.center,
  86. children: [
  87. Expanded(child: _buildItemLeftSection(context, ref, item, _vm)),
  88. Container(
  89. width: 120,
  90. child: _buildItemRightSection(context, ref, item, _vm),
  91. // child: TextButton(onPressed: (){}, child: Text("fdsfds")),
  92. ),
  93. ],
  94. ).paddingOnly(left: 20,right: 20),
  95. ).constrained(
  96. minHeight: 70,
  97. ),
  98. ],
  99. ).onTap(() {
  100. // 去详情
  101. _vm.goNewsDetail(item);
  102. }),
  103. ).marginOnly(left: 15, bottom: 15, right: 15);
  104. }
  105. // list
  106. Widget _buildSaleList(BuildContext context, WidgetRef ref, _vm) {
  107. List itemsList = _vm.state.list.toList();
  108. return ListView.builder(
  109. itemCount: itemsList.length,
  110. itemBuilder: (context, index) {
  111. return _buildSaleItem(context, ref, itemsList[index], _vm);
  112. },
  113. );
  114. }
  115. @override
  116. Widget build(BuildContext context, WidgetRef ref) {
  117. final _vm = ref.read(documentsVmProvider.notifier);
  118. return Scaffold(
  119. // appBar: AppBar(title: Text("资产")),
  120. body: Container(
  121. child: EasyRefresh(
  122. // 上拉加载
  123. onLoad: () async {
  124. Log.d("----onLoad");
  125. _vm.onLoadData();
  126. },
  127. // 下拉刷新
  128. onRefresh: () async {
  129. Log.d("----onRefresh");
  130. _vm.refreshListData();
  131. },
  132. child: Container(
  133. color: ColorUtils.string2Color('#F2F3F6'),
  134. padding: const EdgeInsets.only(top: 15),
  135. child: _buildSaleList(context, ref, _vm)),
  136. )),
  137. );
  138. }
  139. }