documents_page.dart 5.0 KB

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