chooseVisitTimeContent.dart 8.6 KB

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