Files
syncrow-app/lib/features/devices/bloc/ac/ac_cubit.dart
T
Mohammad Salameh 5a9c96b0a8 Built Curtains List view
Modified Category Model(default value of devices status is now null)
Added a category getter in each devices cubit ( AcCubit, LightsCubit ...)
2024-03-05 12:36:57 +03:00

57 lines
1.5 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.categories[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;
}