Files
syncrow-app/lib/features/devices/bloc/ac/ac_cubit.dart
T
Mohammad Salameh b3fcca639a Removed location from models
Added the spaces models
Added the rooms models
Added the Spaces cubit
Implemented the home dropdown functionality
2024-03-06 21:34:23 +03:00

57 lines
1.6 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_category_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);
static DevicesCategoryModel category = DevicesCubit.allCategories[0];
ACModel? getSelectedAC() {
for (var ac in category.devices) {
if (ac is ACModel && ac.isSelected) {
return ac;
}
}
return null;
}
void setTempToAll(double temperature) {
for (DeviceModel ac in category.devices) {
if (ac is ACModel) {
if (ac.temperature != temperature &&
ac.bounds.min <= temperature &&
temperature <= ac.bounds.max) {
setACTemp(ac, temperature);
}
}
}
universalACTemp = temperature;
emit(ACsTempChanged(temperature));
}
void setACTemp(ACModel model, double temp) {
if (model.bounds.min <= temp && temp <= model.bounds.max) {
model.temperature = temp;
}
emit(ACsTempChanged(temp));
}
double getTemp(int index) {
var device = category.devices[index];
if (device is ACModel) {
return device.temperature;
}
return 0.0; // or any default value you prefer
}
static double universalACTemp = 20;
}