facility_deposit_screen.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import 'package:auto_route/auto_route.dart';
  2. import 'package:cs_resources/generated/l10n.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_hooks/flutter_hooks.dart';
  6. import 'package:hooks_riverpod/hooks_riverpod.dart';
  7. import 'package:widgets/ext/ex_widget.dart';
  8. import 'package:widgets/load_state_layout.dart';
  9. import 'package:widgets/my_text_view.dart';
  10. import 'package:widgets/widget_export.dart';
  11. import '../../detail/facility_detail_page.dart';
  12. import 'facility_deposit_view_model.dart';
  13. import 'item_facility_deposit.dart';
  14. @RoutePage()
  15. class FacilityDepositScreen extends HookConsumerWidget {
  16. @override
  17. Widget build(BuildContext context, WidgetRef ref) {
  18. final viewModel = ref.read(facilityDepositViewModelProvider.notifier);
  19. final state = ref.watch(facilityDepositViewModelProvider);
  20. useEffect(() {
  21. // 组件挂载时执行 - 执行接口请求
  22. Future.microtask(() => viewModel.fetchList());
  23. return () {
  24. // 组件卸载时执行
  25. };
  26. }, []);
  27. return SizedBox(
  28. width: double.infinity,
  29. height: double.infinity,
  30. child: EasyRefresh(
  31. controller: viewModel.refreshController,
  32. onRefresh: viewModel.onRefresh,
  33. child: LoadStateLayout(
  34. state: state.loadingState,
  35. errorMessage: state.errorMessage,
  36. errorRetry: () {
  37. viewModel.retryRequest();
  38. },
  39. successSliverWidget: [
  40. // 头布局
  41. _buildHeaderWidget(context, ref),
  42. // 列表
  43. SliverList(
  44. delegate: SliverChildBuilderDelegate(
  45. (context, index) {
  46. return FacilityDepositItem(index: index, item: state.datas[index]).onTap(() {
  47. FacilityDetailPage.startInstance(context: context,bookingId: state.datas[index].booking?.id);
  48. });
  49. },
  50. childCount: state.datas.length,
  51. )),
  52. //脚布局
  53. _buildFootWidget(context, ref),
  54. ],
  55. ),
  56. ).marginOnly(top: 5, bottom: 5),
  57. );
  58. }
  59. //头布局
  60. _buildHeaderWidget(BuildContext context, WidgetRef ref) {
  61. final state = ref.watch(facilityDepositViewModelProvider);
  62. return SliverToBoxAdapter(
  63. child: Container(
  64. width: double.infinity,
  65. margin: const EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 5),
  66. child: Column(
  67. children: [
  68. // 上半部分
  69. Container(
  70. width: double.infinity,
  71. padding: const EdgeInsets.all(16),
  72. decoration: BoxDecoration(
  73. color: context.appColors.btnBgDefault,
  74. borderRadius: const BorderRadius.only(
  75. topLeft: Radius.circular(5),
  76. topRight: Radius.circular(5),
  77. ),
  78. ),
  79. child: MyTextView(
  80. S.current.deposit_amount,
  81. fontSize: 18,
  82. textAlign: TextAlign.center,
  83. isFontMedium: true,
  84. textColor: Colors.white,
  85. ),
  86. ),
  87. // 下半部分
  88. Container(
  89. width: double.infinity,
  90. padding: const EdgeInsets.all(26),
  91. decoration: BoxDecoration(
  92. color: context.appColors.whiteSecondBG,
  93. borderRadius: const BorderRadius.only(
  94. bottomLeft: Radius.circular(5),
  95. bottomRight: Radius.circular(5),
  96. ),
  97. ),
  98. child: MyTextView(
  99. "\$ ${state.totalDeposit ?? "-"}",
  100. fontSize: 29,
  101. fontWeight: FontWeight.w600,
  102. textAlign: TextAlign.center,
  103. textColor: context.appColors.textBlack,
  104. ),
  105. ),
  106. ],
  107. ),
  108. ),
  109. );
  110. }
  111. /// 构建页面底部组件
  112. ///
  113. /// [BuildContext context] 用于访问当前构建上下文,以便获取主题颜色等信息
  114. /// [WidgetRef ref] 用于访问和操作应用状态
  115. ///
  116. /// 返回一个SliverToBoxAdapter,它包含一个列布局,其中包含两个文本视图
  117. /// 第一个文本视图显示存款描述的标题,第二个文本视图显示具体的存款描述文本
  118. _buildFootWidget(BuildContext context, WidgetRef ref) {
  119. return SliverToBoxAdapter(
  120. child: Column(
  121. crossAxisAlignment: CrossAxisAlignment.start,
  122. children: [
  123. // 显示存款描述标题的文本视图
  124. MyTextView(
  125. S.current.deposit_desc,
  126. fontSize: 20,
  127. marginTop: 14,
  128. marginRight: 15,
  129. marginLeft: 20,
  130. isFontMedium: true,
  131. textColor: context.appColors.textBlack,
  132. ),
  133. // 显示具体存款描述文本的文本视图
  134. MyTextView(
  135. S.current.deposit_desc_txt,
  136. marginTop: 14,
  137. marginBottom: 14,
  138. marginRight: 15,
  139. marginLeft: 20,
  140. fontSize: 15,
  141. isFontRegular: true,
  142. textColor: context.appColors.textBlack,
  143. ),
  144. ],
  145. ),
  146. );
  147. }
  148. }