chooseAirConditionContent_vm.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:riverpod_annotation/riverpod_annotation.dart';
  4. import 'package:router/ext/auto_router_extensions.dart';
  5. import 'package:shared/utils/log_utils.dart';
  6. import 'package:widgets/dialog/dialog_content_wrap.dart';
  7. import '../../../respository/services_respository.dart';
  8. import 'chooseAirConditionContent_state.dart';
  9. part 'chooseAirConditionContent_vm.g.dart';
  10. List<Map<String, dynamic>> airConditionList = [
  11. {
  12. "name": "Hanging air conditioner (unit)",
  13. "id": 1,
  14. "price": 40.0,
  15. },
  16. {
  17. "name": "Cabinet air conditioner (unit)",
  18. "id": 2,
  19. "price": 50.0,
  20. },
  21. {
  22. "name": "Cylindrical air conditioner (unit)",
  23. "id": 3,
  24. "price": 60.0,
  25. },
  26. {
  27. "name": "Central air conditioning (group)",
  28. "id": 4,
  29. "price": 70.0,
  30. },
  31. ];
  32. ChooseAirConditionContentState initState(){
  33. Log.d("--------------------------initState---------------------");
  34. List<AirConditionContentItem> airConditionListNew = [];
  35. airConditionList.forEach((item) {
  36. AirConditionContentItem newItem = AirConditionContentItem()..id = item['id']..price = item['price'] as double..name = item['name']..num = 1;
  37. airConditionListNew.add(newItem);
  38. });
  39. return ChooseAirConditionContentState(
  40. airConditionList: airConditionListNew,
  41. );
  42. }
  43. @riverpod
  44. class ChooseAirConditionContentVm extends _$ChooseAirConditionContentVm {
  45. late ServicesRespository serviceRespositoryInstance;
  46. @override
  47. ChooseAirConditionContentState build(){
  48. // 引入数据仓库
  49. serviceRespositoryInstance = ref.read(servicesRespositoryProvider);
  50. ChooseAirConditionContentState state = initState();
  51. Log.d("--------------------------build---------------------");
  52. return state;
  53. }
  54. handlerChangeNum(BuildContext context, int num, int index){
  55. state.airConditionList[index].num = num;
  56. state = state.copyWith(
  57. airConditionList: state.airConditionList,
  58. );
  59. }
  60. }