Files
syncrow-app/lib/features/devices/bloc/ac/ac_cubit.dart
Mohammad Salameh 136987c56a built Lights List
2024-03-03 13:05:34 +03:00

69 lines
1.7 KiB
Dart

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';
part 'ac_state.dart';
class AcCubit extends Cubit<AcState> {
AcCubit() : super(AcInitial());
static AcCubit get(context) => BlocProvider.of(context);
void selectAC(ACModel model) {
model.isSelected = !model.isSelected;
emit(ACSelected());
}
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 (var element in DevicesCubit.categories[0].devices) {
if (element is ACModel) {
element.temperature = temperature;
}
}
emit(ACsTempChanged(temperature));
}
void increaseACTemp(int index) {
var device = DevicesCubit.categories[0].devices[index];
if (device is ACModel) {
device.temperature += 0.5;
emit(ACsTempChanged(device.temperature));
}
}
void decreaseACTemp(int index) {
var device = DevicesCubit.categories[0].devices[index];
if (device is ACModel) {
device.temperature -= 0.5;
emit(ACsTempChanged(device.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 averageTemp = 0;
/// implement the fan speed and temp mode change
}