import 'package:domain/entity/paid_service_detail_entity.dart'; 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 'chooseHouseCleanContent_state.dart'; part 'chooseHouseCleanContent_vm.g.dart'; @riverpod class ChooseHouseCleanContentVm extends _$ChooseHouseCleanContentVm { late ServicesRespository serviceRespositoryInstance; List _products = []; List> houseCleanList = []; ChooseHouseCleanContentState initState(){ Log.d("--------------------------initState---------------------"); if(houseCleanList.isNotEmpty){ List houseCleanListNew = []; houseCleanList.forEach((item) { HouseCleanContentItem newItem = HouseCleanContentItem() ..id = item['id'] ..price = item['price'] as double ..name = item['name'] ..num = 1 ..areaSizeRange = item['areaSizeRange'] ..isChecked = item['isChecked'] ..isDisable = item['isDisable']; houseCleanListNew.add(newItem); }); return ChooseHouseCleanContentState( houseCleanList: houseCleanListNew, ); }else { return ChooseHouseCleanContentState( houseCleanList: null, ); } } @override ChooseHouseCleanContentState build(){ // 引入数据仓库 serviceRespositoryInstance = ref.read(servicesRespositoryProvider); ChooseHouseCleanContentState state = initState(); Log.d("--------------------------build---------------------"); return state; } setInitPageData(BuildContext context, Map? params){ Log.d("--------------------------setInitPageData----------$params-----------"); _products = params?['products']??[]; // 渲染一帧后 WidgetsBinding.instance.addPostFrameCallback((_){ // 修改 state 中 HouseCleanList if(_products != null){ if(_products != null && _products.isNotEmpty){ List products = _products; List houseCleanListNew = []; products.forEach((item) { HouseCleanContentItem newItem = HouseCleanContentItem() ..id = item.id ..price = (item.price ?? 0.0).toDouble() ..name = item.name ..num = 1 ..areaSizeRange = item.shortDescription ..isChecked = false ..isDisable = false; houseCleanListNew.add(newItem); }); state = state.copyWith( houseCleanList: houseCleanListNew, ); } } }); } // 修改 item 的选中状态 handlerChangeItemChecked(BuildContext context, bool isChecked, int index){ List newHouseCleanList = state.houseCleanList!; newHouseCleanList?[index].isChecked = isChecked; state = state.copyWith( houseCleanList: newHouseCleanList, ); } }