123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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<PaidServiceDetailProducts> _products = [];
- List<Map<String, dynamic>> houseCleanList = [];
- ChooseHouseCleanContentState initState(){
- Log.d("--------------------------initState---------------------");
- if(houseCleanList.isNotEmpty){
- List<HouseCleanContentItem> 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<String, dynamic>? params){
- Log.d("--------------------------setInitPageData----------$params-----------");
- _products = params?['products']??[];
- // 渲染一帧后
- WidgetsBinding.instance.addPostFrameCallback((_){
- // 修改 state 中 HouseCleanList
- if(_products != null){
- if(_products != null && _products.isNotEmpty){
- List<PaidServiceDetailProducts> products = _products;
- List<HouseCleanContentItem> 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<HouseCleanContentItem> newHouseCleanList = state.houseCleanList!;
- newHouseCleanList?[index].isChecked = isChecked;
- state = state.copyWith(
- houseCleanList: newHouseCleanList,
- );
- }
- }
|