chooseAirConditionContent.dart 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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: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/log_utils.dart';
  9. import 'package:widgets/my_text_view.dart';
  10. import 'package:widgets/widget_export.dart';
  11. import 'package:widgets/my_cart_num.dart';
  12. import 'chooseAirConditionContent_state.dart';
  13. import 'chooseAirConditionContent_vm.dart';
  14. class ChooseAirConditionContent extends HookConsumerWidget {
  15. final int id;
  16. final int serviceTypeCode;
  17. const ChooseAirConditionContent({Key? key,required this.id, required this.serviceTypeCode}) : super(key: key);
  18. @override
  19. Widget build(BuildContext context, WidgetRef ref) {
  20. final vm = ref.read(chooseAirConditionContentVmProvider.notifier);
  21. final state = ref.watch(chooseAirConditionContentVmProvider);
  22. final totalPrice = ref.watch(chooseAirConditionContentVmProvider.select((state)=>state.totalPrice));
  23. useEffect((){
  24. // 组件挂载时执行 - 执行接口请求
  25. // Future.microtask(() => vm.initPageData());
  26. return () {
  27. // 组件卸载时执行
  28. };
  29. },[]);
  30. return Column(
  31. mainAxisAlignment: MainAxisAlignment.start,
  32. crossAxisAlignment: CrossAxisAlignment.start,
  33. children: List.generate(state.airConditionList.length, (index){
  34. return _buildItem(context, state.airConditionList[index], index, vm, totalPrice);
  35. }),
  36. );
  37. }
  38. Widget _buildItem(BuildContext context, AirConditionContentItem airConditionItem, int index, ChooseAirConditionContentVm vm,double totalPrice){
  39. final title = airConditionItem.name??'';
  40. final num = airConditionItem.num?? 1;
  41. final price = airConditionItem.price?? 0;
  42. return Container(
  43. padding: EdgeInsets.only(left: 15, right: 15, top: 0, bottom: 0),
  44. child: Column(
  45. children: [
  46. Row(
  47. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  48. mainAxisSize: MainAxisSize.max,
  49. children: [
  50. Expanded(
  51. child: MyTextView(
  52. title,
  53. fontSize: 15,
  54. isFontRegular: true,
  55. textColor: context.appColors.textDarkGray,
  56. ),
  57. ),
  58. MyCartNum(onChange: (value){
  59. vm.handlerChangeNum(context, value, index);
  60. })
  61. ],
  62. ),
  63. Divider(),
  64. ],
  65. ),
  66. );
  67. }
  68. }