documents_page.dart 5.9 KB

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