mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
Refactor device status handling and update UI components
- Update device status handling from 'status' to 'isOnline' for consistency - Remove unused imports and redundant code related to light switches - Refactor UI components to use 'isOnline' instead of 'status' for device status
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
@ -7,7 +10,9 @@ import 'package:syncrow_app/features/app_layout/view/widgets/app_body.dart';
|
||||
import 'package:syncrow_app/features/app_layout/view/widgets/default_app_bar.dart';
|
||||
import 'package:syncrow_app/features/app_layout/view/widgets/default_nav_bar.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_switches.dart';
|
||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class AppLayout extends StatelessWidget {
|
||||
@ -53,6 +58,18 @@ class AppLayout extends StatelessWidget {
|
||||
appBar: DefaultAppBar(),
|
||||
body: AppBody(),
|
||||
bottomNavigationBar: DefaultNavBar(),
|
||||
// floatingActionButton: FloatingActionButton(
|
||||
// onPressed: () {
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// CustomPageRoute(
|
||||
// builder: (context) =>
|
||||
// const ThreeGangSwitchesView(),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// child: const Icon(Icons.arrow_forward_ios_sharp),
|
||||
// ),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
@ -12,7 +12,7 @@ import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/gateway/gateway_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/lights_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights_switches/light_switches.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_switches.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_view.dart';
|
||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||
import 'package:syncrow_app/services/api/network_exception.dart';
|
||||
@ -63,14 +63,14 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
switch (category.type) {
|
||||
case DeviceType.AC:
|
||||
return const ACsView();
|
||||
case DeviceType.Lights:
|
||||
case DeviceType.LightBulb:
|
||||
return const LightsView();
|
||||
case DeviceType.DoorLock:
|
||||
return const DoorView();
|
||||
case DeviceType.Curtain:
|
||||
return const CurtainView();
|
||||
case DeviceType.ThreeGang:
|
||||
return const LightSwitchesView();
|
||||
return const ThreeGangSwitchesView();
|
||||
case DeviceType.Gateway:
|
||||
return const GateWayView();
|
||||
default:
|
||||
@ -125,14 +125,14 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
category.devicesStatus = !category.devicesStatus!;
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = category.devicesStatus;
|
||||
device.isOnline = category.devicesStatus;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
category.devicesStatus = true;
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = true;
|
||||
device.isOnline = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -142,7 +142,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
}
|
||||
|
||||
turnOnOffDevice(DeviceModel device) {
|
||||
device.status = !device.status!;
|
||||
device.isOnline = !device.isOnline!;
|
||||
DevicesCategoryModel category = allCategories!.firstWhere((category) {
|
||||
if (category.devices != null) {
|
||||
return category.devices!.contains(device);
|
||||
@ -157,10 +157,10 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
updateDevicesStatus(DevicesCategoryModel category) {
|
||||
if (category.devices != null) {
|
||||
if (category.devices!.isNotEmpty) {
|
||||
bool? tempStatus = category.devices![0].status;
|
||||
bool? tempStatus = category.devices![0].isOnline;
|
||||
for (var ac in category.devices!) {
|
||||
//check if there any ac have a different status than the initial ==> turn off the universal switch
|
||||
if (ac.status != tempStatus) {
|
||||
if (ac.isOnline != tempStatus) {
|
||||
category.devicesStatus = null;
|
||||
emit(DeviceSwitchChanged());
|
||||
return;
|
||||
@ -179,7 +179,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
if (category.devices != null) {
|
||||
if (category.devices!.isNotEmpty) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = false;
|
||||
device.isOnline = false;
|
||||
}
|
||||
changeCategorySwitchValue(category);
|
||||
updateDevicesStatus(category);
|
||||
@ -192,7 +192,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
if (category.devices != null) {
|
||||
if (category.devices!.isNotEmpty) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = true;
|
||||
device.isOnline = true;
|
||||
}
|
||||
changeCategorySwitchValue(category);
|
||||
updateDevicesStatus(category);
|
||||
@ -204,7 +204,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
areAllDevicesOff(DevicesCategoryModel category) {
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
if (device.status ?? false) {
|
||||
if (device.isOnline ?? false) {
|
||||
category.devicesStatus = false;
|
||||
emit(CategorySwitchChanged());
|
||||
return;
|
||||
@ -276,7 +276,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
// }
|
||||
//
|
||||
// toggleLight(DeviceModel light) {
|
||||
// light.status != null ? light.status = !light.status! : light.status = true;
|
||||
// light.isOnline != null ? light.isOnline = !light.isOnline! : light.isOnline = true;
|
||||
// emit(LightToggled(light));
|
||||
// }
|
||||
//
|
||||
@ -296,45 +296,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
// emit(LightBrightnessChanged(value));
|
||||
// }
|
||||
// }
|
||||
|
||||
///ACs
|
||||
// DeviceModel? getSelectedAC() {
|
||||
// for (var ac in category.devices) {
|
||||
// if (ac is DeviceModel && ac.isSelected) {
|
||||
// return ac;
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// void setTempToAll(double temperature) {
|
||||
// for (DeviceModel ac in category.devices) {
|
||||
// if (ac is DeviceModel) {
|
||||
// if (ac.temperature != temperature &&
|
||||
// ac.bounds.min <= temperature &&
|
||||
// temperature <= ac.bounds.max) {
|
||||
// setACTemp(ac, temperature);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// universalACTemp = temperature;
|
||||
// emit(ACsTempChanged(temperature));
|
||||
// }
|
||||
//
|
||||
// void setACTemp(DeviceModel 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 DeviceModel) {
|
||||
// return device.temperature;
|
||||
// }
|
||||
// return 0.0; // or any default value you prefer
|
||||
// }
|
||||
}
|
||||
|
||||
enum LightMode {
|
||||
|
@ -24,9 +24,9 @@ class DevicesCategoryModel {
|
||||
//sets the initial status of the devices
|
||||
if (devices != null) {
|
||||
if (devices!.isNotEmpty) {
|
||||
bool tempStatus = devices!.first.status ?? false;
|
||||
bool tempStatus = devices!.first.isOnline ?? false;
|
||||
for (var device in devices!) {
|
||||
if (device.status != tempStatus) {
|
||||
if (device.isOnline != tempStatus) {
|
||||
devicesStatus = false;
|
||||
break;
|
||||
}
|
||||
@ -41,9 +41,9 @@ class DevicesCategoryModel {
|
||||
DevicesCategoryModel.fromJson(Map<String, dynamic> json)
|
||||
: name = json['groupName'],
|
||||
id = json['groupId'],
|
||||
type = deviceTypeMap[json['groupName']] ?? DeviceType.Other,
|
||||
type = devicesTypesMap[json['productType']] ?? DeviceType.Other,
|
||||
icon = deviceTypeIconMap[
|
||||
deviceTypeMap[json['groupName']] ?? DeviceType.Other] ??
|
||||
devicesTypesMap[json['productType']] ?? DeviceType.Other] ??
|
||||
'',
|
||||
devices = [],
|
||||
isSelected = false;
|
||||
@ -53,22 +53,14 @@ class DevicesCategoryModel {
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, DeviceType> deviceTypeMap = {
|
||||
'Ceiling Presence Sensors': DeviceType.Sensors,
|
||||
'Wall presence sensor': DeviceType.Sensors,
|
||||
'Door Locks': DeviceType.DoorLock,
|
||||
'Gateways': DeviceType.Gateway,
|
||||
'ACs': DeviceType.AC,
|
||||
'3Gang': DeviceType.Gang,
|
||||
};
|
||||
|
||||
Map<DeviceType, String> deviceTypeIconMap = {
|
||||
DeviceType.AC: Assets.iconsAC,
|
||||
DeviceType.Lights: Assets.iconsLight,
|
||||
DeviceType.LightBulb: Assets.iconsLight,
|
||||
DeviceType.DoorLock: Assets.iconsDoorLock,
|
||||
DeviceType.Curtain: Assets.iconsCurtain,
|
||||
DeviceType.Gateway: Assets.iconsGateway,
|
||||
DeviceType.Sensors: Assets.iconsSensors,
|
||||
DeviceType.Gang: Assets.iconsGang,
|
||||
DeviceType.CeilingSensor: Assets.iconsSensors,
|
||||
DeviceType.WallSensor: Assets.iconsSensors,
|
||||
DeviceType.ThreeGang: Assets.iconsGang,
|
||||
DeviceType.Other: Assets.iconsAC,
|
||||
};
|
||||
|
@ -1,46 +1,116 @@
|
||||
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class DeviceModel {
|
||||
final int? id;
|
||||
final String? name;
|
||||
final DeviceType? type;
|
||||
bool? status;
|
||||
final String? image;
|
||||
final double? timer;
|
||||
late final String icon;
|
||||
int? activeTime;
|
||||
String? category;
|
||||
String? categoryName;
|
||||
int? createTime;
|
||||
String? gatewayId;
|
||||
String? icon;
|
||||
String? id;
|
||||
String? ip;
|
||||
double? lat;
|
||||
String? localKey;
|
||||
double? lon;
|
||||
String? model;
|
||||
String? name;
|
||||
String? nodeId; //rmeove
|
||||
bool? isOnline;
|
||||
String? ownerId; //remove
|
||||
String? productId; //remove
|
||||
String? productName;
|
||||
bool? isSub;
|
||||
String? timeZone;
|
||||
int? updateTime;
|
||||
String? uuid;
|
||||
DeviceType? productType;
|
||||
bool isSelected = false;
|
||||
|
||||
late List<FunctionModel> functions;
|
||||
|
||||
DeviceModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.status,
|
||||
required this.image,
|
||||
required this.timer,
|
||||
required this.functions,
|
||||
this.activeTime,
|
||||
this.category,
|
||||
this.categoryName,
|
||||
this.createTime,
|
||||
this.gatewayId,
|
||||
this.icon,
|
||||
this.id,
|
||||
this.ip,
|
||||
this.lat,
|
||||
this.localKey,
|
||||
this.lon,
|
||||
this.model,
|
||||
this.name,
|
||||
this.nodeId,
|
||||
this.isOnline,
|
||||
this.ownerId,
|
||||
this.productId,
|
||||
this.productName,
|
||||
this.isSub,
|
||||
this.timeZone,
|
||||
this.updateTime,
|
||||
this.uuid,
|
||||
this.productType,
|
||||
}) {
|
||||
switch (type) {
|
||||
case DeviceType.AC:
|
||||
icon = Assets.iconsAC;
|
||||
break;
|
||||
case DeviceType.Lights:
|
||||
icon = Assets.iconsLight;
|
||||
break;
|
||||
case DeviceType.DoorLock:
|
||||
icon = Assets.iconsDoorLock;
|
||||
break;
|
||||
case DeviceType.Curtain:
|
||||
icon = Assets.iconsCurtain;
|
||||
break;
|
||||
case DeviceType.Gateway:
|
||||
icon = Assets.iconsGateway;
|
||||
break;
|
||||
default:
|
||||
icon = '';
|
||||
}
|
||||
functions = getFunctions(productType!);
|
||||
}
|
||||
|
||||
factory DeviceModel.fromJson(Map<String, dynamic> json) {
|
||||
return DeviceModel(
|
||||
activeTime: json['activeTime'],
|
||||
category: json['category'],
|
||||
categoryName: json['categoryName'],
|
||||
createTime: json['createTime'],
|
||||
gatewayId: json['gatewayId'],
|
||||
icon: json['icon'],
|
||||
id: json['id'],
|
||||
ip: json['ip'],
|
||||
lat: double.tryParse(json['lat']),
|
||||
localKey: json['localKey'],
|
||||
lon: double.tryParse(json['lon']),
|
||||
model: json['model'],
|
||||
name: json['name'],
|
||||
nodeId: json['nodeId'],
|
||||
isOnline: json['online'],
|
||||
ownerId: json['ownerId'],
|
||||
productId: json['productId'],
|
||||
productName: json['productName'],
|
||||
isSub: json['sub'],
|
||||
timeZone: json['timeZone'],
|
||||
updateTime: json['updateTime'],
|
||||
uuid: json['uuid'],
|
||||
productType: devicesTypesMap[json['productName']] ?? DeviceType.Other,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'activeTime': activeTime,
|
||||
'category': category,
|
||||
'categoryName': categoryName,
|
||||
'createTime': createTime,
|
||||
'gatewayId': gatewayId,
|
||||
'icon': icon,
|
||||
'id': id,
|
||||
'ip': ip,
|
||||
'lat': lat,
|
||||
'localKey': localKey,
|
||||
'lon': lon,
|
||||
'model': model,
|
||||
'name': name,
|
||||
'nodeId': nodeId,
|
||||
'online': isOnline,
|
||||
'ownerId': ownerId,
|
||||
'productId': productId,
|
||||
'productName': productName,
|
||||
'sub': isSub,
|
||||
'timeZone': timeZone,
|
||||
'updateTime': updateTime,
|
||||
'uuid': uuid,
|
||||
'productType': productType,
|
||||
};
|
||||
}
|
||||
|
||||
List<FunctionModel> getFunctions(DeviceType type) =>
|
||||
devicesFunctionsMap[productType] ?? [];
|
||||
}
|
||||
|
@ -1,21 +1,10 @@
|
||||
//{
|
||||
// "code": "switch_1",
|
||||
// "desc": "switch 1",
|
||||
// "name": "switch 1",
|
||||
// "type": "Boolean",
|
||||
// "values": "{}"
|
||||
// }
|
||||
class FunctionModel {
|
||||
String? code;
|
||||
String? desc;
|
||||
String? name;
|
||||
String? type;
|
||||
String? values;
|
||||
|
||||
FunctionModel({
|
||||
required this.code,
|
||||
required this.desc,
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.values,
|
||||
});
|
||||
@ -23,8 +12,6 @@ class FunctionModel {
|
||||
factory FunctionModel.fromJson(Map<String, dynamic> json) {
|
||||
return FunctionModel(
|
||||
code: json['code'],
|
||||
desc: json['desc'],
|
||||
name: json['name'],
|
||||
type: json['type'],
|
||||
values: json['values'],
|
||||
);
|
||||
@ -33,8 +20,6 @@ class FunctionModel {
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'code': code,
|
||||
'desc': desc,
|
||||
'name': name,
|
||||
'type': type,
|
||||
'values': values,
|
||||
};
|
||||
|
@ -28,7 +28,7 @@ class LightInterfaceSwitch extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
BodyLarge(
|
||||
text: light.status ?? false
|
||||
text: light.isOnline ?? false
|
||||
? StringsManager.on
|
||||
: StringsManager.off,
|
||||
style:
|
||||
@ -37,7 +37,7 @@ class LightInterfaceSwitch extends StatelessWidget {
|
||||
Container(
|
||||
width: 35,
|
||||
decoration: ShapeDecoration(
|
||||
color: light.status ?? false
|
||||
color: light.isOnline ?? false
|
||||
? ColorsManager.primaryColorWithOpacity
|
||||
: Colors.grey,
|
||||
shape: const CircleBorder(),
|
||||
|
@ -1,71 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class LightSwitch extends StatelessWidget {
|
||||
const LightSwitch({
|
||||
super.key,
|
||||
required this.control,
|
||||
});
|
||||
|
||||
final DeviceControlModel control;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return state is DeviceControlLoading
|
||||
? const CircularProgressIndicator()
|
||||
: InkWell(
|
||||
overlayColor: MaterialStateProperty.all(Colors.transparent),
|
||||
onTap: () {
|
||||
DevicesCubit.get(context)
|
||||
.deviceControl(control)
|
||||
.then((value) {
|
||||
print('Device control response: $value');
|
||||
if (control.value ?? true) {
|
||||
control.value = false;
|
||||
} else {
|
||||
control.value = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Stack(
|
||||
alignment: !control.value!
|
||||
? Alignment.topCenter
|
||||
: Alignment.bottomCenter,
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(100.0)),
|
||||
color: !control.value!
|
||||
? ColorsManager.primaryColorWithOpacity
|
||||
: ColorsManager.switchOffColor,
|
||||
),
|
||||
width: 60,
|
||||
height: 115,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(5.0),
|
||||
child: SizedBox.square(
|
||||
dimension: 60,
|
||||
child: SvgPicture.asset(
|
||||
!control.value!
|
||||
? Assets.iconsLightSwitchOn
|
||||
: Assets.iconsLightSwitchOff,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights_switches/light_switches_body.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class LightSwitchesView extends StatelessWidget {
|
||||
const LightSwitchesView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Scaffold(
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar: const CategoryViewAppBar(),
|
||||
body: BlocBuilder<HomeCubit, HomeState>(
|
||||
builder: (context, state) {
|
||||
return Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(
|
||||
Assets.imagesBackground,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
opacity: 0.4,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: Constants.appBarHeight,
|
||||
left: Constants.defaultPadding,
|
||||
right: Constants.defaultPadding,
|
||||
bottom: Constants.bottomNavBarHeight,
|
||||
),
|
||||
child: LightSwitchesBody(
|
||||
device: DeviceModel(
|
||||
id: 2,
|
||||
name: 'Bedroom Light',
|
||||
type: DeviceType.Lights,
|
||||
status: true,
|
||||
timer: 0,
|
||||
image: '',
|
||||
functions: [
|
||||
FunctionModel(
|
||||
code: 'switch_1',
|
||||
desc: 'switch 1',
|
||||
name: 'switch 1',
|
||||
type: 'Boolean',
|
||||
values: '{}'),
|
||||
FunctionModel(
|
||||
code: 'switch_2',
|
||||
desc: 'switch 2',
|
||||
name: 'switch 2',
|
||||
type: 'Boolean',
|
||||
values: '{}'),
|
||||
FunctionModel(
|
||||
code: 'switch_3',
|
||||
desc: 'switch 3',
|
||||
name: 'switch 3',
|
||||
type: 'Boolean',
|
||||
values: '{}'),
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,260 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights_switches/light_switch.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class LightSwitchesBody extends StatelessWidget {
|
||||
const LightSwitchesBody({
|
||||
super.key,
|
||||
required this.device,
|
||||
});
|
||||
|
||||
final DeviceModel device;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Expanded(child: SizedBox.shrink()),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
LightSwitch(
|
||||
control: DeviceControlModel(
|
||||
deviceId: 'bfe10693d4fd263206ocq9',
|
||||
code: 'switch_1',
|
||||
value: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(
|
||||
width: 70,
|
||||
child: BodySmall(
|
||||
text: "Bedside Light",
|
||||
fontColor: ColorsManager.textPrimaryColor,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
LightSwitch(
|
||||
control: DeviceControlModel(
|
||||
deviceId: 'bfe10693d4fd263206ocq9',
|
||||
code: 'switch_2',
|
||||
value: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(
|
||||
width: 70,
|
||||
child: BodySmall(
|
||||
text: "Ceiling Light",
|
||||
fontColor: ColorsManager.textPrimaryColor,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
LightSwitch(
|
||||
control: DeviceControlModel(
|
||||
deviceId: 'bfe10693d4fd263206ocq9',
|
||||
code: 'switch_3',
|
||||
value: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(
|
||||
width: 70,
|
||||
child: BodySmall(
|
||||
text: "Spotlight",
|
||||
fontColor: ColorsManager.textPrimaryColor,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 3,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
child: Center(
|
||||
child: BodySmall(
|
||||
text: "On",
|
||||
style: context.bodyMedium.copyWith(
|
||||
color:
|
||||
ColorsManager.primaryColorWithOpacity,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
BodySmall(
|
||||
text: "All On",
|
||||
style: context.bodyMedium.copyWith(
|
||||
color: ColorsManager.textPrimaryColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 3,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.access_time,
|
||||
color: ColorsManager.primaryColorWithOpacity,
|
||||
size: 25,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
BodySmall(
|
||||
text: "Timer",
|
||||
style: context.bodyMedium.copyWith(
|
||||
color: ColorsManager.textPrimaryColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 3,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
child: Center(
|
||||
child: BodySmall(
|
||||
text: "Off",
|
||||
style: context.bodyMedium.copyWith(
|
||||
color:
|
||||
ColorsManager.primaryColorWithOpacity,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
BodySmall(
|
||||
text: "All Off",
|
||||
style: context.bodyMedium.copyWith(
|
||||
color: ColorsManager.textPrimaryColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ class RoomPageSwitch extends StatelessWidget {
|
||||
// ),
|
||||
// );
|
||||
|
||||
if (device.type == DeviceType.AC) {
|
||||
if (device.productType == DeviceType.AC) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CustomPageRoute(
|
||||
@ -54,7 +54,7 @@ class RoomPageSwitch extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
device.icon,
|
||||
device.icon!,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
CustomSwitch(
|
||||
|
@ -19,7 +19,7 @@ class CustomSwitch extends StatelessWidget {
|
||||
builder: (context, state) {
|
||||
bool? status;
|
||||
if (device != null) {
|
||||
status = device!.status;
|
||||
status = device!.isOnline;
|
||||
} else if (category != null) {
|
||||
status = category!.devicesStatus;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: model.status ?? false
|
||||
color: model.isOnline ?? false
|
||||
? ColorsManager.primaryColor
|
||||
: Colors.white,
|
||||
borderRadius: const BorderRadius.only(
|
||||
@ -39,7 +39,7 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "ON",
|
||||
fontColor: model.status ?? false ? Colors.white : null,
|
||||
fontColor: model.isOnline ?? false ? Colors.white : null,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
@ -54,7 +54,7 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: model.status ?? false
|
||||
color: model.isOnline ?? false
|
||||
? Colors.white
|
||||
: ColorsManager.primaryColor,
|
||||
borderRadius: const BorderRadius.only(
|
||||
@ -65,7 +65,7 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "OFF",
|
||||
fontColor: model.status ?? false ? null : Colors.white,
|
||||
fontColor: model.isOnline ?? false ? null : Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user