mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 22:14:55 +00:00
Converted all the devices models to extends from DeviceModel for the purpose of unifying.
Initialized Lights feature.
This commit is contained in:
@ -1,21 +1,51 @@
|
||||
class ACModel {
|
||||
final String name;
|
||||
final String id;
|
||||
late bool status;
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
|
||||
class ACModel extends DeviceModel {
|
||||
late double temperature;
|
||||
|
||||
late int fanSpeed;
|
||||
|
||||
late int tempMode;
|
||||
|
||||
bool isSelected = false;
|
||||
|
||||
ACModel({
|
||||
required this.name,
|
||||
required this.id,
|
||||
required this.status,
|
||||
required this.temperature,
|
||||
required this.fanSpeed,
|
||||
required this.tempMode,
|
||||
required super.id,
|
||||
required super.name,
|
||||
required super.type,
|
||||
required super.status,
|
||||
required super.location,
|
||||
required super.image,
|
||||
required super.timer,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'temperature': temperature,
|
||||
'fanSpeed': fanSpeed,
|
||||
'tempMode': tempMode,
|
||||
'id': id,
|
||||
'name': name,
|
||||
'status': status,
|
||||
'type': type,
|
||||
'location': location,
|
||||
'image': image,
|
||||
};
|
||||
}
|
||||
|
||||
factory ACModel.fromJson(Map<String, dynamic> json) {
|
||||
return ACModel(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
status: json['status'],
|
||||
temperature: json['temperature'],
|
||||
fanSpeed: json['fanSpeed'],
|
||||
tempMode: json['tempMode'],
|
||||
type: json['type'],
|
||||
location: json['location'],
|
||||
image: json['image'],
|
||||
timer: json['timer'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import 'ac_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
|
||||
class DevicesCategoryModel {
|
||||
final String name;
|
||||
@ -9,7 +8,7 @@ class DevicesCategoryModel {
|
||||
final Widget page;
|
||||
|
||||
bool devicesStatus = false;
|
||||
final List<ACModel> devices;
|
||||
final List<DeviceModel> devices;
|
||||
|
||||
final DeviceType type;
|
||||
bool isSelected;
|
||||
@ -23,7 +22,7 @@ class DevicesCategoryModel {
|
||||
required this.devices}) {
|
||||
//sets the initial status of the devices
|
||||
if (devices.isNotEmpty) {
|
||||
bool tempStatus = devices.first.status;
|
||||
bool tempStatus = devices.first.status ?? false;
|
||||
for (var device in devices) {
|
||||
if (device.status != tempStatus) {
|
||||
devicesStatus = false;
|
||||
|
||||
20
lib/features/devices/model/device_model.dart
Normal file
20
lib/features/devices/model/device_model.dart
Normal file
@ -0,0 +1,20 @@
|
||||
abstract class DeviceModel {
|
||||
final String? id;
|
||||
final String? name;
|
||||
final String? type;
|
||||
bool? status;
|
||||
final String? location;
|
||||
final String? image;
|
||||
final double? timer;
|
||||
bool isSelected = false;
|
||||
|
||||
DeviceModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.status,
|
||||
required this.location,
|
||||
required this.image,
|
||||
required this.timer,
|
||||
});
|
||||
}
|
||||
51
lib/features/devices/model/light_model.dart
Normal file
51
lib/features/devices/model/light_model.dart
Normal file
@ -0,0 +1,51 @@
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
|
||||
class LightModel extends DeviceModel {
|
||||
final double brightness;
|
||||
final int color;
|
||||
|
||||
final int lightingMode;
|
||||
|
||||
LightModel({
|
||||
required this.brightness,
|
||||
required this.color,
|
||||
required this.lightingMode,
|
||||
required super.id,
|
||||
required super.name,
|
||||
required super.type,
|
||||
required super.status,
|
||||
required super.location,
|
||||
required super.image,
|
||||
required super.timer,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'luminance': brightness,
|
||||
'color': color,
|
||||
'lightingMode': lightingMode,
|
||||
'timer': timer,
|
||||
'id': id,
|
||||
'name': name,
|
||||
'status': status,
|
||||
'type': type,
|
||||
'location': location,
|
||||
'image': image,
|
||||
};
|
||||
}
|
||||
|
||||
factory LightModel.fromJson(Map<String, dynamic> json) {
|
||||
return LightModel(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
status: json['status'],
|
||||
brightness: json['luminance'],
|
||||
color: json['color'],
|
||||
lightingMode: json['lightingMode'],
|
||||
timer: json['timer'],
|
||||
type: json['type'],
|
||||
location: json['location'],
|
||||
image: json['image'],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user