Files
syncrow-app/lib/features/devices/bloc/ac/ac_cubit.dart
Mohammad Salameh d9a3f9e2a0 code refactoring
2024-03-03 19:07:24 +03:00

48 lines
1.2 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';
import 'package:syncrow_app/features/devices/model/device_model.dart';
part 'ac_state.dart';
class AcCubit extends Cubit<AcState> {
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;
}