facility_deposit_screen.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import 'package:auto_route/auto_route.dart';
  2. import 'package:cpt_facility/modules/facility/active/item_facility_active.dart';
  3. import 'package:cs_resources/generated/l10n.dart';
  4. import 'package:cs_resources/theme/app_colors_theme.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_hooks/flutter_hooks.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:widgets/ext/ex_widget.dart';
  9. import 'package:widgets/load_state_layout.dart';
  10. import 'package:widgets/my_text_view.dart';
  11. import 'package:widgets/widget_export.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]);
  47. },
  48. childCount: state.datas.length,
  49. )),
  50. //脚布局
  51. _buildFootWidget(context, ref),
  52. ],
  53. ),
  54. ).marginOnly(top: 5, bottom: 5),
  55. );
  56. }
  57. //头布局
  58. _buildHeaderWidget(BuildContext context, WidgetRef ref) {
  59. return SliverToBoxAdapter(
  60. child: Container(
  61. width: double.infinity,
  62. margin: const EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 5),
  63. child: Column(
  64. children: [
  65. // 上半部分
  66. Container(
  67. width: double.infinity,
  68. padding: const EdgeInsets.all(16),
  69. decoration: BoxDecoration(
  70. color: context.appColors.btnBgDefault,
  71. borderRadius: const BorderRadius.only(
  72. topLeft: Radius.circular(5),
  73. topRight: Radius.circular(5),
  74. ),
  75. ),
  76. child: MyTextView(
  77. S.current.deposit_amount,
  78. fontSize: 18,
  79. textAlign: TextAlign.center,
  80. isFontMedium: true,
  81. textColor: Colors.white,
  82. ),
  83. ),
  84. // 下半部分
  85. Container(
  86. width: double.infinity,
  87. padding: EdgeInsets.all(26),
  88. decoration: const BoxDecoration(
  89. color: Colors.white,
  90. borderRadius: BorderRadius.only(
  91. bottomLeft: Radius.circular(5),
  92. bottomRight: Radius.circular(5),
  93. ),
  94. ),
  95. child: MyTextView(
  96. "\$ 200.00",
  97. fontSize: 30,
  98. isFontBold: true,
  99. textAlign: TextAlign.center,
  100. textColor: Colors.black,
  101. ),
  102. ),
  103. ],
  104. ),
  105. ),
  106. );
  107. }
  108. //底部的说明文本脚布局
  109. _buildFootWidget(BuildContext context, WidgetRef ref) {
  110. return SliverToBoxAdapter(
  111. child: Column(
  112. crossAxisAlignment: CrossAxisAlignment.start,
  113. children: [
  114. MyTextView(
  115. S.current.deposit_desc,
  116. fontSize: 20,
  117. marginTop: 14,
  118. marginRight: 15,
  119. marginLeft: 20,
  120. isFontMedium: true,
  121. textColor: context.appColors.textBlack,
  122. ),
  123. MyTextView(
  124. S.current.deposit_desc_txt,
  125. marginTop: 14,
  126. marginBottom: 14,
  127. marginRight: 15,
  128. marginLeft: 20,
  129. fontSize: 15,
  130. isFontRegular: true,
  131. textColor: context.appColors.textBlack,
  132. ),
  133. ],
  134. ),
  135. );
  136. }
  137. }