123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- 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 'chooseAirConditionContent_state.dart';
- part 'chooseAirConditionContent_vm.g.dart';
- @riverpod
- class ChooseAirConditionContentVm extends _$ChooseAirConditionContentVm {
- late ServicesRespository serviceRespositoryInstance;
- List<PaidServiceDetailProducts> _products = [];
- List<Map<String, dynamic>> airConditionList = [];
- ChooseAirConditionContentState initState(){
- Log.d("--------------------------initState---------------------");
- if(airConditionList.isNotEmpty){
- List<AirConditionContentItem> airConditionListNew = [];
- airConditionList.forEach((item) {
- AirConditionContentItem newItem = AirConditionContentItem()
- ..id = item['id']
- ..price = double.tryParse(item['price'] ?? '')
- ..name = item['name']
- ..num = 1;
- airConditionListNew.add(newItem);
- });
- return ChooseAirConditionContentState(
- airConditionList: airConditionListNew,
- );
- }else {
- return ChooseAirConditionContentState(
- airConditionList: [],
- );
- }
- }
- @override
- ChooseAirConditionContentState build(){
- // 引入数据仓库
- serviceRespositoryInstance = ref.read(servicesRespositoryProvider);
- ChooseAirConditionContentState 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<AirConditionContentItem> airConditionListNew = [];
- products.forEach((item) {
- AirConditionContentItem newItem = AirConditionContentItem()
- ..id = item.id
- ..price = (item.price ?? 0.0).toDouble()
- ..name = item.name
- ..num = 1;
- airConditionListNew.add(newItem);
- });
- state = state.copyWith(
- airConditionList: airConditionListNew,
- );
- }
- }
- });
- }
- handlerChangeNum(BuildContext context, int num, int index){
- state.airConditionList[index].num = num;
- state = state.copyWith(
- airConditionList: state.airConditionList,
- );
- }
- }
|