chooseVisitTimeContent.dart 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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/generated/assets.dart';
  7. import 'package:cs_resources/generated/l10n.dart';
  8. import 'package:cs_resources/theme/app_colors_theme.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:auto_route/auto_route.dart';
  11. import 'package:flutter_hooks/flutter_hooks.dart';
  12. import 'package:hooks_riverpod/hooks_riverpod.dart';
  13. import 'package:shared/utils/color_utils.dart';
  14. import 'package:shared/utils/ext_dart.dart';
  15. import 'package:shared/utils/log_utils.dart';
  16. import 'package:widgets/ext/ex_widget.dart';
  17. import 'package:widgets/load_state_layout.dart';
  18. import 'package:widgets/my_button.dart';
  19. import 'package:widgets/my_load_image.dart';
  20. import 'package:widgets/my_text_view.dart';
  21. import 'package:widgets/widget_export.dart';
  22. import 'package:widgets/my_cart_num.dart';
  23. import 'chooseVisitTimeContent_state.dart';
  24. // import 'chooseVisitTimeContent_vm.dart';
  25. class ChooseVisitTimeContent extends HookConsumerWidget {
  26. final int id;
  27. final String cleanServiceType;
  28. final double contentTopSectionHeight;
  29. final double contentMaxHeight;
  30. final double bottomBtnSectionHeight;
  31. const ChooseVisitTimeContent({
  32. Key? key,
  33. required this.id,
  34. required this.cleanServiceType,
  35. this.contentTopSectionHeight = 150,
  36. this.contentMaxHeight = 480,
  37. this.bottomBtnSectionHeight = 50,
  38. }):super(key: key);
  39. @override
  40. Widget build(BuildContext context, WidgetRef ref) {
  41. final vm = ref.read(chooseVisitTimeContentVmProvider.notifier);
  42. final state = ref.watch(chooseVisitTimeContentVmProvider);
  43. useEffect((){
  44. vm.setInitPageData(context, id, cleanServiceType);
  45. // 组件挂载时执行 - 执行接口请求
  46. Future.microtask(() => vm.initPageData(context));
  47. return () {
  48. // 组件卸载时执行
  49. };
  50. },[]);
  51. return LayoutBuilder(
  52. builder: (BuildContext context, BoxConstraints constraints) {
  53. // final maxHeight = constraints.maxHeight;
  54. // final minHeight = constraints.minHeight;
  55. // final maxWidth = constraints.maxWidth;
  56. // Log.d("---maxHeight-----$maxHeight-- $minHeight $maxWidth--");
  57. // double scrollMaxHeight = contentMaxHeight - contentTopSectionHeight - bottomBtnSectionHeight ;
  58. // Log.d("scrollMaxHeight $scrollMaxHeight");
  59. return Container(
  60. width: double.infinity,
  61. // width: 80,
  62. color: ColorUtils.string2Color("#F5F5F7"),
  63. padding: const EdgeInsets.only(left:20, right: 20, top: 12, bottom: 12),
  64. constraints: const BoxConstraints(
  65. minHeight: 0,
  66. maxHeight: 280,
  67. ),
  68. child: LoadStateLayout(
  69. state: state.loadingState,
  70. successSliverWidget: state.visitTimeList!=null && state.visitTimeList.isNotEmpty?[
  71. SliverGrid(
  72. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  73. crossAxisCount: 4,
  74. mainAxisSpacing: 15,
  75. crossAxisSpacing: 5,
  76. childAspectRatio: 80 / 38,
  77. // childAspectRatio: 166.5/214 * ScreenUtil.getAdapterSizeCtx(context, 166.5/214), // 宽高比
  78. // childAspectRatio: 166.5/214 * ((166.5/214).ap), //
  79. ),
  80. delegate: SliverChildBuilderDelegate(
  81. (context, index) {
  82. return _buildTimeItem(context, index, state.visitTimeList[index], ref, vm);
  83. },
  84. childCount: state.visitTimeList.length,
  85. ),
  86. )
  87. ]: [
  88. SliverList( delegate: SliverChildBuilderDelegate(
  89. (context, index){
  90. return const Center(
  91. child: SizedBox(
  92. height: 250,
  93. child: MyAssetImage(Assets.baseServicePageNoData, width: 123.5, height: 115.5, fit: BoxFit.contain),
  94. ),
  95. );
  96. },
  97. childCount: 1
  98. ),)
  99. ],
  100. ),
  101. );
  102. }
  103. );
  104. }
  105. Widget _buildTimeItem(BuildContext context,int index, VisitTimeContentItem item, WidgetRef ref, vm){
  106. final state = ref.watch(chooseVisitTimeContentVmProvider);
  107. final itemIsChecked = ref.watch(chooseVisitTimeContentVmProvider.select((state) =>
  108. state.visitTimeList[index].isChecked ?? false
  109. ));
  110. final timeText = item.timeText;
  111. return HookBuilder(
  112. builder: (context) {
  113. final isMultiSelect = useState<bool>(state.isMultiSelect??false);
  114. // final isChecked = useState<bool>(itemIsChecked??false);
  115. final enable = useState<bool>(item.enable??false);
  116. final urgent = useState<bool>(item.urgent??false); // 是否加急
  117. final holiday = useState<bool>(item.holiday??false); // 是否节假日
  118. final night = useState<bool>(item.night??false); // 是否晚上
  119. return SizedBox(
  120. width: 80,
  121. child: Stack(
  122. children: [
  123. Container(
  124. decoration: BoxDecoration(
  125. color: itemIsChecked? ColorUtils.string2Color("#D9DFF6"):context.appColors.whiteBG,
  126. borderRadius: BorderRadius.circular(8),
  127. boxShadow: [
  128. BoxShadow(
  129. color: ColorUtils.string2Color('#E5E5E5'),
  130. offset: const Offset(0, 2),
  131. blurRadius: 8,
  132. ),
  133. ],
  134. ),
  135. child: MyButton(
  136. onPressed: (){
  137. if(enable.value){
  138. // 可选 - 点击时间
  139. vm.handlerTimeItemClick(context, index,!itemIsChecked);
  140. }
  141. },
  142. text: '$timeText',
  143. padding: const EdgeInsets.only(left: 5, right: 5, top: 5, bottom: 5),
  144. textColor: itemIsChecked ?context.appColors.textPrimary: context.appColors.textDarkGray999,
  145. enable: enable.value,
  146. disabledBackgroundColor: context.appColors.disEnableGray,
  147. disabledTextColor: context.appColors.textWhite,
  148. fontSize: 11,
  149. fontWeight: FontWeight.w400,
  150. )
  151. ),
  152. // 加急
  153. Positioned(
  154. left: 0,
  155. top: 0,
  156. child: urgent.value? MyTextView(
  157. S.current.extreme_speed,
  158. textColor: ColorUtils.string2Color("#DD6800"),
  159. fontSize: 8,
  160. isFontRegular: true,
  161. backgroundColor:ColorUtils.string2Color("#FFEBD9"),
  162. paddingTop: 2,
  163. paddingBottom: 2,
  164. paddingLeft: 5,
  165. paddingRight: 5,
  166. ).clipRRect(
  167. topLeft: 8,
  168. bottomRight: 8
  169. ): const SizedBox.shrink(),
  170. ),
  171. // 夜间
  172. Positioned(
  173. left: 0,
  174. bottom: 0,
  175. child: night.value? MyTextView(
  176. S.current.night,
  177. textColor: ColorUtils.string2Color("#FE4066"),
  178. fontSize: 8,
  179. isFontRegular: true,
  180. backgroundColor: ColorUtils.string2Color("#FE4066").withOpacity(0.2),
  181. paddingTop: 2,
  182. paddingBottom: 2,
  183. paddingLeft: 5,
  184. paddingRight: 5,
  185. ).clipRRect(
  186. topRight: 8,
  187. bottomLeft: 8
  188. ): const SizedBox.shrink(),
  189. ),
  190. // 节假日
  191. Positioned(
  192. right: 0,
  193. bottom: 0,
  194. child: holiday.value? MyTextView(
  195. S.current.holiday,
  196. textColor: ColorUtils.string2Color("#37d7cc"),
  197. fontSize: 8,
  198. isFontRegular: true,
  199. backgroundColor:ColorUtils.string2Color("#68f1e7").withOpacity(0.2),
  200. paddingTop: 2,
  201. paddingBottom: 2,
  202. paddingLeft: 5,
  203. paddingRight: 5,
  204. ).clipRRect(
  205. topLeft: 8,
  206. bottomRight: 8
  207. ): const SizedBox.shrink(),
  208. ),
  209. ],
  210. ),
  211. );
  212. }
  213. );
  214. }
  215. }