mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 14:54:54 +00:00
33 lines
900 B
Dart
33 lines
900 B
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);
|
|
|
|
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);
|
|
}
|
|
}
|