light interface

This commit is contained in:
Mohammad Salameh
2024-03-04 14:38:48 +03:00
parent 79e0b7ec21
commit 7ecac02a8a
12 changed files with 341 additions and 67 deletions
@@ -94,6 +94,12 @@ class DevicesCubit extends Cubit<DevicesState> {
type: '',
location: '',
image: '',
recentColors: [
0xFF83D9FF,
0xFFFC3E81,
0xFFC0FF66,
0xFFFDC242,
],
),
LightModel(
name: "Master Bedroom Light",
@@ -106,6 +112,12 @@ class DevicesCubit extends Cubit<DevicesState> {
type: '',
location: '',
image: '',
recentColors: [
0xFF83D9FF,
0xFFFC3E81,
0xFFC0FF66,
0xFFFDC242,
],
),
LightModel(
name: "Kitchen Light",
@@ -118,6 +130,12 @@ class DevicesCubit extends Cubit<DevicesState> {
type: '',
location: '',
image: '',
recentColors: [
0xFF83D9FF,
0xFFFC3E81,
0xFFC0FF66,
0xFFFDC242,
],
),
LightModel(
name: "Bathroom Light",
@@ -130,6 +148,12 @@ class DevicesCubit extends Cubit<DevicesState> {
type: '',
location: '',
image: '',
recentColors: [
0xFF83D9FF,
0xFFFC3E81,
0xFFC0FF66,
0xFFFDC242,
],
),
LightModel(
name: "Balcony Light",
@@ -142,6 +166,12 @@ class DevicesCubit extends Cubit<DevicesState> {
type: '',
location: '',
image: '',
recentColors: [
0xFF83D9FF,
0xFFFC3E81,
0xFFC0FF66,
0xFFFDC242,
],
),
],
icon: Assets.iconsLight,
@@ -8,11 +8,29 @@ class LightsCubit extends Cubit<LightsState> {
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();
}
@@ -35,3 +53,10 @@ class LightsCubit extends Cubit<LightsState> {
setBrightness(light, newBrightness);
}
}
enum LightMode {
Doze,
Relax,
Reading,
Energizing,
}
@@ -25,3 +25,15 @@ class LightToggled extends LightsState {
LightToggled(this.light);
}
class LightColorChanged extends LightsState {
final int color;
LightColorChanged(this.color);
}
class LightModeChanged extends LightsState {
final LightMode mode;
LightModeChanged(this.mode);
}