chooseVisitTimeContent.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import 'package:cpt_services/components/chooseHouseCleanContent_vm.dart';
  2. import 'package:cpt_services/components/chooseVisitTimeBottomFooter.dart';
  3. import 'package:cpt_services/components/chooseVisitTimeBottomFooter_vm.dart';
  4. import 'package:cpt_services/components/chooseVisitTimeContent_vm.dart';
  5. import 'package:cpt_services/components/status_card_item.dart';
  6. import 'package:cs_resources/theme/app_colors_theme.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:auto_route/auto_route.dart';
  9. import 'package:flutter_hooks/flutter_hooks.dart';
  10. import 'package:hooks_riverpod/hooks_riverpod.dart';
  11. import 'package:shared/utils/color_utils.dart';
  12. import 'package:shared/utils/ext_dart.dart';
  13. import 'package:shared/utils/log_utils.dart';
  14. import 'package:widgets/ext/ex_widget.dart';
  15. import 'package:widgets/load_state_layout.dart';
  16. import 'package:widgets/my_button.dart';
  17. import 'package:widgets/my_text_view.dart';
  18. import 'package:widgets/widget_export.dart';
  19. import 'package:widgets/my_cart_num.dart';
  20. import 'chooseVisitTimeContent_state.dart';
  21. // import 'chooseVisitTimeContent_vm.dart';
  22. class ChooseVisitTimeContent extends HookConsumerWidget {
  23. final int id;
  24. final int serviceTypeCode;
  25. final double contentTopSectionHeight;
  26. final double contentMaxHeight;
  27. final double bottomBtnSectionHeight;
  28. const ChooseVisitTimeContent({
  29. Key? key,
  30. required this.id,
  31. required this.serviceTypeCode,
  32. this.contentTopSectionHeight = 150,
  33. this.contentMaxHeight = 480,
  34. this.bottomBtnSectionHeight = 50,
  35. }):super(key: key);
  36. @override
  37. Widget build(BuildContext context, WidgetRef ref) {
  38. final vm = ref.read(chooseVisitTimeContentVmProvider.notifier);
  39. final state = ref.watch(chooseVisitTimeContentVmProvider);
  40. useEffect((){
  41. // 组件挂载时执行 - 执行接口请求
  42. Future.microtask(() => vm.initPageData(context));
  43. return () {
  44. // 组件卸载时执行
  45. };
  46. },[]);
  47. return LayoutBuilder(
  48. builder: (BuildContext context, BoxConstraints constraints) {
  49. // final maxHeight = constraints.maxHeight;
  50. // final minHeight = constraints.minHeight;
  51. // final maxWidth = constraints.maxWidth;
  52. // Log.d("---maxHeight-----$maxHeight-- $minHeight $maxWidth--");
  53. double scrollMaxHeight = contentMaxHeight - contentTopSectionHeight - bottomBtnSectionHeight ;
  54. // Log.d("scrollMaxHeight $scrollMaxHeight");
  55. return Container(
  56. width: double.infinity,
  57. // width: 80,
  58. color: ColorUtils.string2Color("#F5F5F7"),
  59. padding: const EdgeInsets.only(left:20, right: 20, top: 12, bottom: 12),
  60. constraints: const BoxConstraints(
  61. minHeight: 0,
  62. maxHeight: 280,
  63. ),
  64. child: LoadStateLayout(
  65. state: state.loadingState,
  66. successSliverWidget: [
  67. SliverGrid(
  68. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  69. crossAxisCount: 4,
  70. mainAxisSpacing: 5,
  71. crossAxisSpacing: 5,
  72. childAspectRatio: 80 / 38,
  73. // childAspectRatio: 166.5/214 * ScreenUtil.getAdapterSizeCtx(context, 166.5/214), // 宽高比
  74. // childAspectRatio: 166.5/214 * ((166.5/214).ap), //
  75. ),
  76. delegate: SliverChildBuilderDelegate(
  77. (context, index) {
  78. return _buildTimeItem(context, index, state.visitTimeList[index], ref, vm);
  79. },
  80. childCount: state.visitTimeList.length,
  81. ),
  82. // GridView.builder(
  83. // gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  84. // crossAxisCount: 4,
  85. // mainAxisSpacing: 5,
  86. // crossAxisSpacing: 5,
  87. // childAspectRatio: 80 / 38,
  88. // ),
  89. // itemCount: state.visitTimeList.length,
  90. // itemBuilder: (context, index) {
  91. // final item = state.visitTimeList[index];
  92. // return _buildTimeItem(context, index, item, ref, vm);
  93. // },
  94. // )
  95. )
  96. ],
  97. ),
  98. );
  99. }
  100. );
  101. }
  102. Widget _buildTimeItem(BuildContext context,int index, VisitTimeContentItem item, WidgetRef ref, vm){
  103. final name = item.name;
  104. return HookBuilder(
  105. builder: (context) {
  106. final isChecked = useState<bool>(item.isChecked??false);
  107. return SizedBox(
  108. width: 80,
  109. child: Stack(
  110. children: [
  111. Container(
  112. decoration: BoxDecoration(
  113. color: isChecked.value? ColorUtils.string2Color("#D9DFF6"):context.appColors.whiteBG,
  114. borderRadius: BorderRadius.circular(8),
  115. boxShadow: [
  116. BoxShadow(
  117. color: ColorUtils.string2Color('#E5E5E5'),
  118. offset: const Offset(0, 2),
  119. blurRadius: 8,
  120. ),
  121. ],
  122. ),
  123. child: MyButton(
  124. onPressed: (){
  125. isChecked.value = !isChecked.value;
  126. vm.handlerTimeItemClick(context, index, isChecked.value);
  127. },
  128. text: '$name',
  129. minHeight: 38,
  130. textColor: isChecked.value?context.appColors.textPrimary: context.appColors.textDarkGray999,
  131. fontSize: 12,
  132. fontWeight: FontWeight.w400,
  133. )
  134. ),
  135. Positioned(
  136. child: MyTextView(
  137. 'Extreme speed',
  138. textColor: ColorUtils.string2Color("#DD6800"),
  139. fontSize: 8,
  140. isFontRegular: true,
  141. backgroundColor:ColorUtils.string2Color("#FFEBD9"),
  142. paddingTop: 2,
  143. paddingBottom: 2,
  144. paddingLeft: 5,
  145. paddingRight: 5,
  146. ).clipRRect(
  147. topLeft: 10,
  148. bottomRight: 10
  149. ).onTap((){
  150. }),
  151. ),
  152. ],
  153. ),
  154. );
  155. }
  156. );
  157. }
  158. }