mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 09:19:40 +00:00
added Null state from the AC universal switch (in case the status for the ACs are different from each other)
This commit is contained in:
@ -43,11 +43,11 @@ class AcCubit extends Cubit<AcState> {
|
||||
}
|
||||
|
||||
void updateACsStatus() {
|
||||
bool tempStatus = DevicesCubit.categories[0].devices[0].status ?? false;
|
||||
bool? tempStatus = DevicesCubit.categories[0].devices[0].status;
|
||||
for (var AC in DevicesCubit.categories[0].devices) {
|
||||
//check if there any AC have a different status than the initial ==> turn off the universal switch
|
||||
if (AC.status != tempStatus) {
|
||||
DevicesCubit.categories[0].devicesStatus = false;
|
||||
DevicesCubit.categories[0].devicesStatus = null;
|
||||
emit(ACsStatusChanged());
|
||||
return;
|
||||
}
|
||||
|
@ -20,10 +20,18 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
}
|
||||
|
||||
void changeCategorySwitchValue(DevicesCategoryModel category) {
|
||||
category.devicesStatus = !category.devicesStatus;
|
||||
for (var device in category.devices) {
|
||||
device.status = category.devicesStatus;
|
||||
if (category.devicesStatus != null) {
|
||||
category.devicesStatus = !category.devicesStatus!;
|
||||
for (var device in category.devices) {
|
||||
device.status = category.devicesStatus;
|
||||
}
|
||||
} else {
|
||||
category.devicesStatus = true;
|
||||
for (var device in category.devices) {
|
||||
device.status = true;
|
||||
}
|
||||
}
|
||||
|
||||
emit(CategorySwitchChanged());
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ class DevicesCategoryModel {
|
||||
|
||||
final Widget page;
|
||||
|
||||
bool devicesStatus = false;
|
||||
bool? devicesStatus = false;
|
||||
final List<DeviceModel> devices;
|
||||
|
||||
final DeviceType type;
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||
|
||||
import '../../../../../utils/resource_manager/color_manager.dart';
|
||||
import '../../../../shared_widgets/text_widgets/body_medium.dart';
|
||||
@ -13,9 +14,9 @@ class UniversalACSwitch extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//TODO: Move these to String Manager "ON" and "OFF"
|
||||
return BlocBuilder<AcCubit, AcState>(
|
||||
builder: (context, state) {
|
||||
bool? status = DevicesCubit.categories[0].devicesStatus;
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
@ -26,8 +27,10 @@ class UniversalACSwitch extends StatelessWidget {
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: DevicesCubit.categories[0].devicesStatus
|
||||
? ColorsManager.primaryColor
|
||||
color: status != null
|
||||
? status
|
||||
? ColorsManager.primaryColor
|
||||
: Colors.white
|
||||
: Colors.white,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
@ -36,9 +39,11 @@ class UniversalACSwitch extends StatelessWidget {
|
||||
),
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "ON",
|
||||
fontColor: DevicesCubit.categories[0].devicesStatus
|
||||
? Colors.white
|
||||
text: StringsManager.on,
|
||||
fontColor: status != null
|
||||
? status
|
||||
? Colors.white
|
||||
: null
|
||||
: null,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
@ -54,9 +59,11 @@ class UniversalACSwitch extends StatelessWidget {
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: DevicesCubit.categories[0].devicesStatus
|
||||
? Colors.white
|
||||
: ColorsManager.primaryColor,
|
||||
color: status != null
|
||||
? status
|
||||
? Colors.white
|
||||
: ColorsManager.primaryColor
|
||||
: Colors.white,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15),
|
||||
@ -64,10 +71,12 @@ class UniversalACSwitch extends StatelessWidget {
|
||||
),
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "OFF",
|
||||
fontColor: DevicesCubit.categories[0].devicesStatus
|
||||
? null
|
||||
: Colors.white,
|
||||
text: StringsManager.off,
|
||||
fontColor: status != null
|
||||
? status
|
||||
? null
|
||||
: Colors.white
|
||||
: null,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
|
@ -22,8 +22,10 @@ class CustomSwitch extends StatelessWidget {
|
||||
height: 28.0,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
color: category.devicesStatus
|
||||
? ColorsManager.primaryColor
|
||||
color: category.devicesStatus != null
|
||||
? category.devicesStatus!
|
||||
? ColorsManager.primaryColor
|
||||
: const Color(0xFFD9D9D9)
|
||||
: const Color(0xFFD9D9D9),
|
||||
),
|
||||
child: Center(
|
||||
@ -37,16 +39,20 @@ class CustomSwitch extends StatelessWidget {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2.0),
|
||||
child: Container(
|
||||
alignment: category.devicesStatus
|
||||
? Alignment.centerRight
|
||||
alignment: category.devicesStatus != null
|
||||
? category.devicesStatus!
|
||||
? Alignment.centerRight
|
||||
: Alignment.centerLeft
|
||||
: Alignment.centerLeft,
|
||||
child: Container(
|
||||
width: 20.0,
|
||||
height: 20.0,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: category.devicesStatus
|
||||
? ColorsManager.primaryColor
|
||||
color: category.devicesStatus != null
|
||||
? category.devicesStatus!
|
||||
? ColorsManager.primaryColor
|
||||
: Colors.grey
|
||||
: Colors.grey,
|
||||
),
|
||||
),
|
||||
|
@ -22,4 +22,6 @@ class StringsManager {
|
||||
static const winterMode = 'Winter Mode';
|
||||
static const summer = 'Summer';
|
||||
static const summerMode = 'Summer Mode';
|
||||
static const on = 'ON';
|
||||
static const off = 'OFF';
|
||||
}
|
||||
|
Reference in New Issue
Block a user