note_management_page.dart 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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:widgets/ext/ex_widget.dart';
  9. import 'package:widgets/my_appbar.dart';
  10. import 'package:widgets/my_button.dart';
  11. import 'package:widgets/my_text_view.dart';
  12. import 'package:widgets/widget_export.dart';
  13. import '../../router/page/form_page_router.dart';
  14. import 'vm/apply_view_model.dart';
  15. @RoutePage()
  16. class NoteManagementPage extends HookConsumerWidget {
  17. const NoteManagementPage({Key? key}) : super(key: key);
  18. //启动当前页面
  19. static void startInstance({BuildContext? context}) {
  20. if (context != null) {
  21. context.router.push(const NoteManagementPageRoute());
  22. } else {
  23. appRouter.push(const NoteManagementPageRoute());
  24. }
  25. }
  26. @override
  27. Widget build(BuildContext context, WidgetRef ref) {
  28. final viewModel = ref.watch(applyViewModelProvider.notifier);
  29. final state = ref.watch(applyViewModelProvider);
  30. // 使用 useState 来持久化 TextEditingController 和 FocusNode
  31. final textEditingController = useTextEditingController();
  32. final focusNode = useFocusNode();
  33. useEffect(() {
  34. //赋值State的值
  35. Future.microtask(() {});
  36. return () {
  37. // 释放控制器资源
  38. textEditingController.dispose();
  39. focusNode.dispose();
  40. };
  41. }, []);
  42. return WillPopScope(
  43. child: Scaffold(
  44. appBar: MyAppBar.appBar(context, state.applyDetail?['title']),
  45. backgroundColor: context.appColors.backgroundWhite,
  46. body: Column(
  47. crossAxisAlignment: CrossAxisAlignment.start,
  48. children: [
  49. SingleChildScrollView(
  50. scrollDirection: Axis.vertical,
  51. physics: const BouncingScrollPhysics(),
  52. child: Container(
  53. margin: const EdgeInsets.symmetric(horizontal: 15),
  54. width: double.infinity,
  55. child: Column(
  56. mainAxisSize: MainAxisSize.max,
  57. crossAxisAlignment: CrossAxisAlignment.start,
  58. children: [
  59. MyTextView(
  60. S.current.notes_to_management,
  61. fontSize: 17,
  62. marginTop: 30,
  63. marginBottom: 13,
  64. isFontMedium: true,
  65. textColor: context.appColors.textBlack,
  66. ),
  67. //Note to Management 的文本
  68. MyTextView(
  69. state.applyDetail?['detail_data']['note_management_txt'],
  70. fontSize: 15,
  71. marginBottom: 18,
  72. isFontRegular: true,
  73. textColor: context.appColors.textBlack,
  74. ),
  75. //文本框
  76. IgnoreKeyboardDismiss(
  77. child: Container(
  78. height: 190,
  79. padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 15),
  80. decoration: BoxDecoration(
  81. color: context.appColors.authFiledBG,
  82. borderRadius: const BorderRadius.all(Radius.circular(5)),
  83. ),
  84. child: TextField(
  85. cursorColor: context.appColors.authFiledText,
  86. cursorWidth: 1.5,
  87. autofocus: false,
  88. enabled: true,
  89. focusNode: focusNode,
  90. controller: textEditingController,
  91. decoration: InputDecoration(
  92. isDense: true,
  93. isCollapsed: true,
  94. border: InputBorder.none,
  95. hintText: S.current.type_here,
  96. hintStyle: TextStyle(
  97. color: context.appColors.authFiledHint,
  98. fontSize: 15.0,
  99. fontWeight: FontWeight.w500,
  100. ),
  101. ),
  102. style: TextStyle(
  103. color: context.appColors.authFiledText,
  104. fontSize: 15.0,
  105. fontWeight: FontWeight.w500,
  106. ),
  107. textInputAction: TextInputAction.done,
  108. onSubmitted: (value) {
  109. FocusScope.of(context).unfocus();
  110. },
  111. maxLines: null,
  112. expands: true,
  113. onChanged: (text) {
  114. // 当文本改变时
  115. },
  116. ),
  117. ),
  118. ),
  119. ],
  120. ),
  121. ),
  122. ).expanded(),
  123. //底部按钮
  124. MyButton(
  125. onPressed: (){
  126. focusNode.unfocus();
  127. viewModel.gotoNextPage();
  128. },
  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: 0,
  137. ),
  138. ],
  139. )),
  140. onWillPop: () async {
  141. viewModel.handlePopAction();
  142. return true;
  143. });
  144. }
  145. }