attachment_page.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/image/image_nine_grid.dart';
  8. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  9. import 'package:router/ext/auto_router_extensions.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 '../../router/page/form_page_router.dart';
  15. import 'vm/apply_view_model.dart';
  16. @RoutePage()
  17. class AttachmentPage extends HookConsumerWidget {
  18. const AttachmentPage({Key? key}) : super(key: key);
  19. //启动当前页面
  20. static void startInstance({BuildContext? context}) {
  21. if (context != null) {
  22. context.router.push(const AttachmentPageRoute());
  23. } else {
  24. appRouter.push(const AttachmentPageRoute());
  25. }
  26. }
  27. @override
  28. Widget build(BuildContext context, WidgetRef ref) {
  29. final viewModel = ref.watch(applyViewModelProvider.notifier);
  30. final state = ref.watch(applyViewModelProvider);
  31. useEffect(() {
  32. //赋值State的值
  33. Future.microtask(() {});
  34. return () {
  35. // 组件卸载时执行
  36. };
  37. }, []);
  38. return WillPopScope(
  39. child: Scaffold(
  40. appBar: MyAppBar.appBar(context, state.detailPage?['title']),
  41. backgroundColor: context.appColors.backgroundWhite,
  42. body: Column(
  43. crossAxisAlignment: CrossAxisAlignment.start,
  44. children: [
  45. SingleChildScrollView(
  46. scrollDirection: Axis.vertical,
  47. physics: const BouncingScrollPhysics(),
  48. child: Container(
  49. margin: const EdgeInsets.symmetric(horizontal: 15),
  50. width: double.infinity,
  51. child: Column(
  52. mainAxisSize: MainAxisSize.max,
  53. crossAxisAlignment: CrossAxisAlignment.start,
  54. children: [
  55. MyTextView(
  56. S.current.attachments,
  57. fontSize: 17,
  58. marginTop: 30,
  59. marginBottom: 13,
  60. isFontMedium: true,
  61. textColor: context.appColors.textBlack,
  62. ),
  63. //Note to Management 的文本
  64. MyTextView(
  65. state.detailPage?['detail_data']['attachment_txt'],
  66. fontSize: 15,
  67. marginBottom: 14,
  68. isFontRegular: true,
  69. textColor: context.appColors.textBlack,
  70. ),
  71. //选择图片九宫格
  72. ImageNineGrid(
  73. isSelectEnable: state.enableEdit,
  74. maxImages: 10,
  75. spacing: 10,
  76. aspectRatio: 108 / 80,
  77. initialImages: state.formContentDetail.attachments ?? [],
  78. onImagesChanged: (list) {
  79. viewModel.updateFormContentDetail((content) {
  80. content.attachments = list;
  81. });
  82. },
  83. ),
  84. ],
  85. ),
  86. ),
  87. ).expanded(),
  88. //底部按钮
  89. MyButton(
  90. onPressed: () {
  91. if (state.enableEdit){
  92. final attachments = state.formContentDetail.attachments;
  93. if (attachments == null || attachments.isEmpty) {
  94. ToastEngine.show("Select attachments");
  95. return;
  96. }
  97. }
  98. viewModel.gotoNextPage();
  99. },
  100. text: S.current.next,
  101. textColor: Colors.white,
  102. backgroundColor: context.appColors.btnBgDefault,
  103. fontWeight: FontWeight.w500,
  104. type: ClickType.throttle,
  105. fontSize: 16,
  106. minHeight: 50,
  107. radius: 0,
  108. ),
  109. ],
  110. )),
  111. onWillPop: () async {
  112. viewModel.handlePopAction();
  113. return true;
  114. });
  115. }
  116. }