chooseAirConditionContent_vm.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import 'package:domain/entity/paid_service_detail_entity.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:riverpod_annotation/riverpod_annotation.dart';
  5. import 'package:router/ext/auto_router_extensions.dart';
  6. import 'package:shared/utils/log_utils.dart';
  7. import 'package:widgets/dialog/dialog_content_wrap.dart';
  8. import '../../../respository/services_respository.dart';
  9. import 'chooseAirConditionContent_state.dart';
  10. part 'chooseAirConditionContent_vm.g.dart';
  11. @riverpod
  12. class ChooseAirConditionContentVm extends _$ChooseAirConditionContentVm {
  13. late ServicesRespository serviceRespositoryInstance;
  14. List<PaidServiceDetailProducts> _products = [];
  15. List<Map<String, dynamic>> airConditionList = [];
  16. ChooseAirConditionContentState initState(){
  17. Log.d("--------------------------initState---------------------");
  18. if(airConditionList.isNotEmpty){
  19. List<AirConditionContentItem> airConditionListNew = [];
  20. airConditionList.forEach((item) {
  21. AirConditionContentItem newItem = AirConditionContentItem()
  22. ..id = item['id']
  23. ..price = double.tryParse(item['price'] ?? '')
  24. ..name = item['name']
  25. ..num = 1;
  26. airConditionListNew.add(newItem);
  27. });
  28. return ChooseAirConditionContentState(
  29. airConditionList: airConditionListNew,
  30. );
  31. }else {
  32. return ChooseAirConditionContentState(
  33. airConditionList: [],
  34. );
  35. }
  36. }
  37. @override
  38. ChooseAirConditionContentState build(){
  39. // 引入数据仓库
  40. serviceRespositoryInstance = ref.read(servicesRespositoryProvider);
  41. ChooseAirConditionContentState state = initState();
  42. Log.d("--------------------------build---------------------");
  43. return state;
  44. }
  45. setInitPageData(BuildContext context, Map<String, dynamic>? params){
  46. Log.d("--------------------------setInitPageData----------$params-----------");
  47. _products = params?['products']??[];
  48. // 渲染一帧后
  49. WidgetsBinding.instance.addPostFrameCallback((_){
  50. // 修改 state 中 HouseCleanList
  51. if(_products != null){
  52. if(_products != null && _products.isNotEmpty){
  53. List<PaidServiceDetailProducts> products = _products;
  54. List<AirConditionContentItem> airConditionListNew = [];
  55. products.forEach((item) {
  56. AirConditionContentItem newItem = AirConditionContentItem()
  57. ..id = item.id
  58. ..price = (item.price ?? 0.0).toDouble()
  59. ..name = item.name
  60. ..num = 1;
  61. airConditionListNew.add(newItem);
  62. });
  63. state = state.copyWith(
  64. airConditionList: airConditionListNew,
  65. );
  66. }
  67. }
  68. });
  69. }
  70. handlerChangeNum(BuildContext context, int num, int index){
  71. state.airConditionList[index].num = num;
  72. state = state.copyWith(
  73. airConditionList: state.airConditionList,
  74. );
  75. }
  76. }