note_management_page.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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:plugin_platform/engine/toast/toast_engine.dart';
  8. import 'package:router/ext/auto_router_extensions.dart';
  9. import 'package:shared/utils/util.dart';
  10. import 'package:widgets/ext/ex_widget.dart';
  11. import 'package:widgets/my_appbar.dart';
  12. import 'package:widgets/my_button.dart';
  13. import 'package:widgets/my_text_view.dart';
  14. import 'package:widgets/widget_export.dart';
  15. import '../../router/page/form_page_router.dart';
  16. import 'vm/apply_view_model.dart';
  17. @RoutePage()
  18. class NoteManagementPage extends HookConsumerWidget {
  19. const NoteManagementPage({Key? key}) : super(key: key);
  20. //启动当前页面
  21. static void startInstance({BuildContext? context}) {
  22. if (context != null) {
  23. context.router.push(const NoteManagementPageRoute());
  24. } else {
  25. appRouter.push(const NoteManagementPageRoute());
  26. }
  27. }
  28. @override
  29. Widget build(BuildContext context, WidgetRef ref) {
  30. final viewModel = ref.watch(applyViewModelProvider.notifier);
  31. final state = ref.watch(applyViewModelProvider);
  32. // 使用 useState 来持久化 TextEditingController 和 FocusNode
  33. final textEditingController = useTextEditingController();
  34. final focusNode = useFocusNode();
  35. useEffect(() {
  36. //赋值State的值
  37. Future.microtask(() {
  38. textEditingController.text = state.formContentDetail.notesToManagement ?? "";
  39. });
  40. return () {};
  41. }, []);
  42. return WillPopScope(
  43. child: Scaffold(
  44. appBar: MyAppBar.appBar(context, state.detailPage?['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.detailPage?['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: state.enableEdit,
  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. if (state.enableEdit) {
  128. String? notesToManagement = textEditingController.text;
  129. if (Utils.isEmpty(notesToManagement)) {
  130. ToastEngine.show("Enter Notes To Management");
  131. return;
  132. }
  133. viewModel.updateFormContentDetail((content) {
  134. content.notesToManagement = notesToManagement;
  135. });
  136. }
  137. viewModel.gotoNextPage();
  138. },
  139. text: S.current.next,
  140. textColor: Colors.white,
  141. backgroundColor: context.appColors.btnBgDefault,
  142. fontWeight: FontWeight.w500,
  143. type: ClickType.throttle,
  144. fontSize: 16,
  145. minHeight: 50,
  146. radius: 0,
  147. ),
  148. ],
  149. )),
  150. onWillPop: () async {
  151. viewModel.handlePopAction();
  152. return true;
  153. });
  154. }
  155. }