chooseHouseCleanContent.dart 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import 'package:cpt_services/components/status_card_item.dart';
  2. import 'package:cs_resources/theme/app_colors_theme.dart';
  3. import 'package:domain/entity/paid_service_detail_entity.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:auto_route/auto_route.dart';
  6. import 'package:flutter_hooks/flutter_hooks.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:shared/utils/color_utils.dart';
  9. import 'package:shared/utils/log_utils.dart';
  10. import 'package:widgets/my_button.dart';
  11. import 'package:widgets/my_text_view.dart';
  12. import 'package:widgets/widget_export.dart';
  13. import 'package:widgets/my_cart_num.dart';
  14. import 'chooseHouseCleanContent_state.dart';
  15. import 'chooseHouseCleanContent_vm.dart';
  16. class ChooseHouseCleanContent extends HookConsumerWidget {
  17. final int id;
  18. final String cleanServiceType;
  19. final String? useScence;
  20. final List<PaidServiceDetailProducts> products;
  21. const ChooseHouseCleanContent({Key? key,required this.id, required this.cleanServiceType, required this.products, this.useScence}) : super(key: key);
  22. @override
  23. Widget build(BuildContext context, WidgetRef ref) {
  24. final vm = ref.read(chooseHouseCleanContentVmProvider.notifier);
  25. List<HouseCleanContentItem>? houseCleanList = ref.watch(chooseHouseCleanContentVmProvider.select((state) => state.houseCleanList));
  26. useEffect((){
  27. vm.setInitPageData(context, {
  28. 'id': id,
  29. 'cleanServiceType': cleanServiceType,
  30. 'products': products,
  31. 'useScence': useScence,
  32. });
  33. // 组件挂载时执行 - 执行接口请求
  34. // Future.microtask(() => vm.initPageData());
  35. return () {
  36. // 组件卸载时执行
  37. };
  38. },[]);
  39. return Container(
  40. padding: EdgeInsets.only(left: 0, right: 0, top: 10, bottom: 10),
  41. child: Column(
  42. mainAxisAlignment: MainAxisAlignment.start,
  43. crossAxisAlignment: CrossAxisAlignment.start,
  44. children: houseCleanList != null && houseCleanList.isNotEmpty? List.generate(houseCleanList!.length, (index){
  45. HouseCleanContentItem currentItem = houseCleanList![index];
  46. // 如何用ref 去watch state中的 houseCleanList中的第index 变化
  47. return _buildItem(context, currentItem, index, vm);
  48. }): [],
  49. ),
  50. );
  51. }
  52. Widget _buildItem(BuildContext context, HouseCleanContentItem HouseCleanItem, int index, ChooseHouseCleanContentVm vm){
  53. final title = HouseCleanItem.name??'';
  54. final areaSizeRange = HouseCleanItem.areaSizeRange??'';
  55. final num = HouseCleanItem.num?? 1;
  56. final price = HouseCleanItem.price?? 0;
  57. bool isChecked = HouseCleanItem.isChecked??false;
  58. bool disabled = HouseCleanItem.isDisable??false;
  59. if(useScence !=null){
  60. disabled = true;
  61. }else {
  62. disabled = false;
  63. }
  64. final isCheckedState = useState<bool>(isChecked);
  65. final isDisable = useState<bool>(disabled);
  66. return Container(
  67. padding: EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
  68. margin: EdgeInsets.only(left: 15, right: 15, top: 0, bottom: 0),
  69. color: ColorUtils.string2Color('#F8F8F8'),
  70. child: Column(
  71. children: [
  72. Row(
  73. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  74. mainAxisSize: MainAxisSize.max,
  75. children: [
  76. Expanded(
  77. child: Column(
  78. crossAxisAlignment: CrossAxisAlignment.start,
  79. children: [
  80. MyTextView(
  81. title,
  82. fontSize: 16,
  83. isFontMedium: true,
  84. textColor: context.appColors.textBlack,
  85. ),
  86. MyTextView(
  87. areaSizeRange,
  88. fontSize: 15,
  89. isFontRegular: true,
  90. textColor: context.appColors.textDarkGray999,
  91. marginTop: 5,
  92. ),
  93. ],
  94. ),
  95. ),
  96. // MyCartNum(onChange: (value){
  97. // vm.handlerChangeNum(context, value, index);
  98. // })
  99. // MyButton(
  100. // text: '\$$price',
  101. // onPressed: (){
  102. // // vm.handlerChangeNum(context, value, index);
  103. // },
  104. // fontSize: 19,
  105. // fontWeight: FontWeight.w500,
  106. // )
  107. Container(
  108. child: MyButton(
  109. text: '\$$price',
  110. onPressed: (){
  111. if(!isDisable.value){
  112. isCheckedState.value = !isCheckedState.value;
  113. vm.handlerChangeItemChecked(context, isCheckedState.value, index);
  114. }
  115. },
  116. minWidth: 80,
  117. minHeight: 40,
  118. fontSize: 19,
  119. fontWeight: FontWeight.w500,
  120. // enable: !isDisable.value,
  121. textColor: isCheckedState.value? context.appColors.textWhite: context.appColors.textPrimary,
  122. backgroundColor: isCheckedState.value ? context.appColors.textPrimary:context.appColors.textWhite,
  123. disabledBackgroundColor: context.appColors.disEnableGray,
  124. disabledTextColor: context.appColors.textWhite,
  125. ),
  126. ),
  127. ],
  128. ),
  129. // Divider(),
  130. ],
  131. ),
  132. );
  133. }
  134. }