chooseHouseCleanContent.dart 5.2 KB

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