facility_deposit_screen.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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);
  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. return SliverToBoxAdapter(
  62. child: Container(
  63. width: double.infinity,
  64. margin: const EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 5),
  65. child: Column(
  66. children: [
  67. // 上半部分
  68. Container(
  69. width: double.infinity,
  70. padding: const EdgeInsets.all(16),
  71. decoration: BoxDecoration(
  72. color: context.appColors.btnBgDefault,
  73. borderRadius: const BorderRadius.only(
  74. topLeft: Radius.circular(5),
  75. topRight: Radius.circular(5),
  76. ),
  77. ),
  78. child: MyTextView(
  79. S.current.deposit_amount,
  80. fontSize: 18,
  81. textAlign: TextAlign.center,
  82. isFontMedium: true,
  83. textColor: Colors.white,
  84. ),
  85. ),
  86. // 下半部分
  87. Container(
  88. width: double.infinity,
  89. padding: const EdgeInsets.all(26),
  90. decoration: BoxDecoration(
  91. color: context.appColors.whiteSecondBG,
  92. borderRadius: const BorderRadius.only(
  93. bottomLeft: Radius.circular(5),
  94. bottomRight: Radius.circular(5),
  95. ),
  96. ),
  97. child: MyTextView(
  98. "\$ 200.00",
  99. fontSize: 30,
  100. isFontBold: true,
  101. textAlign: TextAlign.center,
  102. textColor: context.appColors.textBlack,
  103. ),
  104. ),
  105. ],
  106. ),
  107. ),
  108. );
  109. }
  110. //底部的说明文本脚布局
  111. _buildFootWidget(BuildContext context, WidgetRef ref) {
  112. return SliverToBoxAdapter(
  113. child: Column(
  114. crossAxisAlignment: CrossAxisAlignment.start,
  115. children: [
  116. MyTextView(
  117. S.current.deposit_desc,
  118. fontSize: 20,
  119. marginTop: 14,
  120. marginRight: 15,
  121. marginLeft: 20,
  122. isFontMedium: true,
  123. textColor: context.appColors.textBlack,
  124. ),
  125. MyTextView(
  126. S.current.deposit_desc_txt,
  127. marginTop: 14,
  128. marginBottom: 14,
  129. marginRight: 15,
  130. marginLeft: 20,
  131. fontSize: 15,
  132. isFontRegular: true,
  133. textColor: context.appColors.textBlack,
  134. ),
  135. ],
  136. ),
  137. );
  138. }
  139. }