mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
63 lines
1.5 KiB
Dart
63 lines
1.5 KiB
Dart
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
|
|
|
part 'lights_state.dart';
|
|
|
|
class LightsCubit extends Cubit<LightsState> {
|
|
LightsCubit() : super(LightsInitial());
|
|
|
|
static LightsCubit get(context) => BlocProvider.of(context);
|
|
|
|
Map<int, LightMode> lightModes = {
|
|
0: LightMode.Doze,
|
|
1: LightMode.Relax,
|
|
2: LightMode.Reading,
|
|
3: LightMode.Energizing,
|
|
};
|
|
|
|
setLightingMode(LightModel light, LightMode mode) {
|
|
light.lightingMode =
|
|
lightModes.entries.firstWhere((element) => element.value == mode).key;
|
|
emit(LightModeChanged(mode));
|
|
}
|
|
|
|
toggleLight(LightModel light) {
|
|
light.status != null ? light.status = !light.status! : light.status = true;
|
|
emit(LightToggled(light));
|
|
}
|
|
|
|
setColor(LightModel light, int color) {
|
|
light.color = color;
|
|
emit(LightColorChanged(color));
|
|
}
|
|
|
|
int getBrightness(LightModel light) {
|
|
return light.brightness.toInt();
|
|
}
|
|
|
|
setBrightness(LightModel light, double value) {
|
|
value = (value / 5).ceil() * 5;
|
|
if (value != light.brightness) {
|
|
light.brightness = value;
|
|
emit(LightBrightnessChanged(value));
|
|
}
|
|
}
|
|
|
|
onHorizontalDragUpdate(LightModel light, double dx, double screenWidth) {
|
|
double newBrightness = (dx / (screenWidth - 15) * 100);
|
|
if (newBrightness > 100) {
|
|
newBrightness = 100;
|
|
} else if (newBrightness < 0) {
|
|
newBrightness = 0;
|
|
}
|
|
setBrightness(light, newBrightness);
|
|
}
|
|
}
|
|
|
|
enum LightMode {
|
|
Doze,
|
|
Relax,
|
|
Reading,
|
|
Energizing,
|
|
}
|