tenant_doc_page.dart 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import 'package:cs_resources/generated/l10n.dart';
  2. import 'package:cs_resources/theme/app_colors_theme.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:auto_route/auto_route.dart';
  5. import 'package:flutter_hooks/flutter_hooks.dart';
  6. import 'package:hooks_riverpod/hooks_riverpod.dart';
  7. import 'package:router/ext/auto_router_extensions.dart';
  8. import 'package:shared/utils/log_utils.dart';
  9. import 'package:widgets/ext/ex_widget.dart';
  10. import 'package:widgets/my_appbar.dart';
  11. import 'package:widgets/my_button.dart';
  12. import 'package:widgets/my_text_view.dart';
  13. import 'package:plugin_platform/platform_export.dart';
  14. import '../../router/page/auth_page_router.dart';
  15. import 'tenant_doc_view_model.dart';
  16. @RoutePage()
  17. class TenantDocPage extends HookConsumerWidget {
  18. TenantDocPage({Key? key}) : super(key: key);
  19. //启动当前页面
  20. static void startInstance({BuildContext? context}) {
  21. if (context != null) {
  22. context.router.push(TenantDocPageRoute());
  23. } else {
  24. appRouter.push(TenantDocPageRoute());
  25. }
  26. }
  27. // 为需要测量的控件创建 GlobalKey
  28. final GlobalKey _appbarKey = GlobalKey();
  29. final GlobalKey _titleKey = GlobalKey();
  30. final GlobalKey _descriptionKey = GlobalKey();
  31. final GlobalKey _description1Key = GlobalKey();
  32. final GlobalKey _description2Key = GlobalKey();
  33. final GlobalKey _nineGridKey = GlobalKey();
  34. final GlobalKey _buttonKey = GlobalKey();
  35. @override
  36. Widget build(BuildContext context, WidgetRef ref) {
  37. final viewModel = ref.read(tenantDocViewModelProvider.notifier);
  38. final state = ref.watch(tenantDocViewModelProvider);
  39. // 获取屏幕高度
  40. final screenHeight = MediaQuery.of(context).size.height;
  41. final statusBarHeight = MediaQuery.of(context).padding.top;
  42. final navigationBarHeight = MediaQuery.of(context).padding.bottom;
  43. useEffect(() {
  44. double usedHeight = 0;
  45. // 组件挂载时执行,获取控件高度
  46. WidgetsBinding.instance.addPostFrameCallback((_) {
  47. // 获取各个控件的高度
  48. usedHeight += _appbarKey.currentContext?.size?.height ?? 0;
  49. usedHeight += _titleKey.currentContext?.size?.height ?? 0;
  50. usedHeight += _descriptionKey.currentContext?.size?.height ?? 0;
  51. usedHeight += _description1Key.currentContext?.size?.height ?? 0;
  52. usedHeight += _description2Key.currentContext?.size?.height ?? 0;
  53. usedHeight += _nineGridKey.currentContext?.size?.height ?? 0;
  54. usedHeight += _buttonKey.currentContext?.size?.height ?? 0;
  55. // 计算剩余空间
  56. double remainingSpace = screenHeight - statusBarHeight - navigationBarHeight - usedHeight - 23 - 21;
  57. Log.d("计算剩余空间:$remainingSpace");
  58. if (remainingSpace > 0) {
  59. // 设置一个状态来存储剩余空间的高度
  60. viewModel.setRemainingSpace(remainingSpace);
  61. }
  62. });
  63. return () {
  64. // 组件卸载时执行
  65. };
  66. }, []);
  67. return Scaffold(
  68. appBar: MyAppBar.appBar(context, "", key: _appbarKey),
  69. backgroundColor: context.appColors.backgroundDefault,
  70. body: Container(
  71. padding: const EdgeInsets.symmetric(horizontal: 15),
  72. width: double.infinity,
  73. child: Column(
  74. mainAxisSize: MainAxisSize.max,
  75. crossAxisAlignment: CrossAxisAlignment.start,
  76. children: [
  77. MyTextView(
  78. key: _titleKey,
  79. S.current.upload_documents,
  80. fontSize: 23.5,
  81. marginTop: 23,
  82. marginBottom: 21,
  83. textAlign: TextAlign.center,
  84. isFontMedium: true,
  85. textColor: context.appColors.textBlack,
  86. ),
  87. MyTextView(
  88. key: _descriptionKey,
  89. S.current.upload_doc_desc,
  90. fontSize: 15,
  91. isFontMedium: true,
  92. textColor: context.appColors.textBlack,
  93. ),
  94. MyTextView(
  95. key: _description1Key,
  96. S.current.upload_doc_desc1,
  97. fontSize: 15,
  98. marginTop: 22,
  99. isFontMedium: true,
  100. textColor: context.appColors.textBlack,
  101. ),
  102. MyTextView(
  103. key: _description2Key,
  104. S.current.upload_doc_desc2,
  105. fontSize: 15,
  106. marginTop: 22,
  107. marginBottom: 24,
  108. isFontMedium: true,
  109. textColor: context.appColors.textBlack,
  110. ),
  111. ImageNineGrid(
  112. key: _nineGridKey,
  113. isSelectEnable: true,
  114. maxImages: 3,
  115. spacing: 10,
  116. aspectRatio: 108 / 80,
  117. initialImages: [],
  118. onImagesChanged: (list) {
  119. viewModel.setDocList(list);
  120. },
  121. ),
  122. SizedBox(
  123. height: state.remainingSpace, // 使用剩余空间的值
  124. ),
  125. //底部的按钮
  126. MyButton(
  127. key: _buttonKey,
  128. onPressed: viewModel.submitDoc,
  129. text: S.current.next,
  130. textColor: Colors.white,
  131. backgroundColor: context.appColors.btnBgDefault,
  132. fontWeight: FontWeight.w500,
  133. type: ClickType.throttle,
  134. fontSize: 16,
  135. minHeight: 50,
  136. radius: 5,
  137. ).marginOnly(top: 30, bottom: 30, left: 18, right: 18),
  138. ],
  139. ),
  140. ),
  141. );
  142. }
  143. }