import 'package:flutter/cupertino.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/model/ac_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; part 'ac_state.dart'; class AcCubit extends Cubit { AcCubit() : super(AcInitial()); static AcCubit get(context) => BlocProvider.of(context); ACModel? getSelectedAC() { for (var ac in DevicesCubit.categories[0].devices) { if (ac is ACModel && ac.isSelected) { return ac; } } return null; } void setTempToAll(double temperature) { for (DeviceModel ac in DevicesCubit.categories[0].devices) { if (ac is ACModel) { setACTemp(ac, temperature); } } universalACTemp = temperature; emit(ACsTempChanged(temperature)); } void setACTemp(ACModel model, double temp) { model.temperature = temp; emit(ACsTempChanged(temp)); } double getTemp(int index) { var device = DevicesCubit.categories[0].devices[index]; if (device is ACModel) { return device.temperature; } return 0.0; // or any default value you prefer } static double universalACTemp = 20; }