import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:router/ext/auto_router_extensions.dart'; import 'package:shared/utils/log_utils.dart'; import 'package:widgets/dialog/dialog_content_wrap.dart'; import '../../../respository/services_respository.dart'; import 'chooseAirConditionContent_state.dart'; part 'chooseAirConditionContent_vm.g.dart'; List> airConditionList = [ { "name": "Hanging air conditioner (unit)", "id": 1, "price": 40.0, }, { "name": "Cabinet air conditioner (unit)", "id": 2, "price": 50.0, }, { "name": "Cylindrical air conditioner (unit)", "id": 3, "price": 60.0, }, { "name": "Central air conditioning (group)", "id": 4, "price": 70.0, }, ]; ChooseAirConditionContentState initState(){ Log.d("--------------------------initState---------------------"); List airConditionListNew = []; airConditionList.forEach((item) { AirConditionContentItem newItem = AirConditionContentItem()..id = item['id']..price = item['price'] as double..name = item['name']..num = 1; airConditionListNew.add(newItem); }); return ChooseAirConditionContentState( airConditionList: airConditionListNew, ); } @riverpod class ChooseAirConditionContentVm extends _$ChooseAirConditionContentVm { late ServicesRespository serviceRespositoryInstance; @override ChooseAirConditionContentState build(){ // 引入数据仓库 serviceRespositoryInstance = ref.read(servicesRespositoryProvider); ChooseAirConditionContentState state = initState(); Log.d("--------------------------build---------------------"); return state; } handlerChangeNum(BuildContext context, int num, int index){ state.airConditionList[index].num = num; state = state.copyWith( airConditionList: state.airConditionList, ); } }