chooseAirConditionContent.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import 'package:cpt_services/components/chooseAirConditionContent_vm.dart';
  2. import 'package:cpt_services/components/status_card_item.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:domain/entity/paid_service_detail_entity.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:auto_route/auto_route.dart';
  7. import 'package:flutter_hooks/flutter_hooks.dart';
  8. import 'package:hooks_riverpod/hooks_riverpod.dart';
  9. import 'package:shared/utils/log_utils.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 'chooseAirConditionContent_state.dart';
  14. import 'chooseAirConditionContent_vm.dart';
  15. class ChooseAirConditionContent extends HookConsumerWidget {
  16. final int id;
  17. final String cleanServiceType;
  18. final List<PaidServiceDetailProducts> products;
  19. const ChooseAirConditionContent({Key? key,required this.id, required this.cleanServiceType, required this.products}) : super(key: key);
  20. @override
  21. Widget build(BuildContext context, WidgetRef ref) {
  22. final vm = ref.read(chooseAirConditionContentVmProvider.notifier);
  23. final state = ref.watch(chooseAirConditionContentVmProvider);
  24. // final totalPrice = ref.watch(chooseAirConditionContentVmProvider.select((state)=>state.totalPrice));
  25. useEffect((){
  26. vm.setInitPageData(context, {
  27. 'id': id,
  28. 'cleanServiceType': cleanServiceType,
  29. 'products': products,
  30. });
  31. // 组件挂载时执行 - 执行接口请求
  32. // Future.microtask(() => vm.initPageData());
  33. return () {
  34. // 组件卸载时执行
  35. };
  36. },[]);
  37. return Column(
  38. mainAxisAlignment: MainAxisAlignment.start,
  39. crossAxisAlignment: CrossAxisAlignment.start,
  40. children: List.generate(state.airConditionList.length, (index){
  41. return _buildItem(context, state.airConditionList[index], index, vm,);
  42. }),
  43. );
  44. }
  45. Widget _buildItem(BuildContext context, AirConditionContentItem airConditionItem, int index, ChooseAirConditionContentVm vm){
  46. final title = airConditionItem.name??'';
  47. final num = airConditionItem.num?? 1;
  48. final price = airConditionItem.price?? 0;
  49. return Container(
  50. padding: EdgeInsets.only(left: 15, right: 15, top: 0, bottom: 0),
  51. child: Column(
  52. children: [
  53. Row(
  54. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  55. mainAxisSize: MainAxisSize.max,
  56. children: [
  57. Expanded(
  58. child: MyTextView(
  59. title,
  60. fontSize: 15,
  61. isFontRegular: true,
  62. textColor: context.appColors.textDarkGray,
  63. ),
  64. ),
  65. MyCartNum(onChange: (value){
  66. vm.handlerChangeNum(context, value, index);
  67. })
  68. ],
  69. ),
  70. Divider(),
  71. ],
  72. ),
  73. );
  74. }
  75. }