connected all apis , create functionality is working

This commit is contained in:
ashrafzarkanisala
2024-06-27 02:35:50 +03:00
parent 9fe25b9bd3
commit 17881694e0
23 changed files with 793 additions and 154 deletions

View File

@ -0,0 +1,222 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
class CreateSceneModel {
/*
{
"unitUuid": "string",
"sceneName": "string",
"decisionExpr": "string",
"actions": [
{
"entityId": "string",
"actionExecutor": "string",
"executorProperty": {
"functionCode": "string",
"functionValue": {},
"delaySeconds": 0
}
}
]
}
*/
String unitUuid;
String sceneName;
String decisionExpr;
List<CreateSceneAction> actions;
CreateSceneModel({
required this.unitUuid,
required this.sceneName,
required this.decisionExpr,
required this.actions,
});
CreateSceneModel copyWith({
String? unitUuid,
String? sceneName,
String? decisionExpr,
List<CreateSceneAction>? actions,
}) {
return CreateSceneModel(
unitUuid: unitUuid ?? this.unitUuid,
sceneName: sceneName ?? this.sceneName,
decisionExpr: decisionExpr ?? this.decisionExpr,
actions: actions ?? this.actions,
);
}
Map<String, dynamic> toMap() {
return {
'unitUuid': unitUuid,
'sceneName': sceneName,
'decisionExpr': decisionExpr,
'actions': actions.map((x) => x.toMap()).toList(),
};
}
factory CreateSceneModel.fromMap(Map<String, dynamic> map) {
return CreateSceneModel(
unitUuid: map['unitUuid'] ?? '',
sceneName: map['sceneName'] ?? '',
decisionExpr: map['decisionExpr'] ?? '',
actions: List<CreateSceneAction>.from(
map['actions']?.map((x) => CreateSceneAction.fromMap(x))),
);
}
String toJson() => json.encode(toMap());
factory CreateSceneModel.fromJson(String source) =>
CreateSceneModel.fromMap(json.decode(source));
@override
String toString() {
return 'CreateSceneModel(unitUuid: $unitUuid, sceneName: $sceneName, decisionExpr: $decisionExpr, actions: $actions)';
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is CreateSceneModel &&
other.unitUuid == unitUuid &&
other.sceneName == sceneName &&
other.decisionExpr == decisionExpr &&
listEquals(other.actions, actions);
}
@override
int get hashCode {
return unitUuid.hashCode ^
sceneName.hashCode ^
decisionExpr.hashCode ^
actions.hashCode;
}
}
class CreateSceneAction {
String entityId;
String actionExecutor;
CreateSceneExecutorProperty executorProperty;
CreateSceneAction({
required this.entityId,
required this.actionExecutor,
required this.executorProperty,
});
CreateSceneAction copyWith({
String? entityId,
String? actionExecutor,
CreateSceneExecutorProperty? executorProperty,
}) {
return CreateSceneAction(
entityId: entityId ?? this.entityId,
actionExecutor: actionExecutor ?? this.actionExecutor,
executorProperty: executorProperty ?? this.executorProperty,
);
}
Map<String, dynamic> toMap() {
return {
'entityId': entityId,
'actionExecutor': actionExecutor,
'executorProperty': executorProperty.toMap(),
};
}
factory CreateSceneAction.fromMap(Map<String, dynamic> map) {
return CreateSceneAction(
entityId: map['entityId'] ?? '',
actionExecutor: map['actionExecutor'] ?? '',
executorProperty:
CreateSceneExecutorProperty.fromMap(map['executorProperty']),
);
}
String toJson() => json.encode(toMap());
factory CreateSceneAction.fromJson(String source) =>
CreateSceneAction.fromMap(json.decode(source));
@override
String toString() =>
'CreateSceneAction(entityId: $entityId, actionExecutor: $actionExecutor, executorProperty: $executorProperty)';
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is CreateSceneAction &&
other.entityId == entityId &&
other.actionExecutor == actionExecutor &&
other.executorProperty == executorProperty;
}
@override
int get hashCode =>
entityId.hashCode ^ actionExecutor.hashCode ^ executorProperty.hashCode;
}
class CreateSceneExecutorProperty {
String functionCode;
dynamic functionValue;
int delaySeconds;
CreateSceneExecutorProperty({
required this.functionCode,
required this.functionValue,
required this.delaySeconds,
});
CreateSceneExecutorProperty copyWith({
String? functionCode,
dynamic functionValue,
int? delaySeconds,
}) {
return CreateSceneExecutorProperty(
functionCode: functionCode ?? this.functionCode,
functionValue: functionValue ?? this.functionValue,
delaySeconds: delaySeconds ?? this.delaySeconds,
);
}
Map<String, dynamic> toMap() {
return {
'functionCode': functionCode,
'functionValue': functionValue,
'delaySeconds': delaySeconds,
};
}
factory CreateSceneExecutorProperty.fromMap(Map<String, dynamic> map) {
return CreateSceneExecutorProperty(
functionCode: map['functionCode'] ?? '',
functionValue: map['functionValue'] ?? '',
delaySeconds: map['delaySeconds']?.toInt() ?? 0,
);
}
String toJson() => json.encode(toMap());
factory CreateSceneExecutorProperty.fromJson(String source) =>
CreateSceneExecutorProperty.fromMap(json.decode(source));
@override
String toString() =>
'CreateSceneExecutorProperty(functionCode: $functionCode, functionValue: $functionValue, delaySeconds: $delaySeconds)';
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is CreateSceneExecutorProperty &&
other.functionCode == functionCode &&
other.functionValue == functionValue &&
other.delaySeconds == delaySeconds;
}
@override
int get hashCode =>
functionCode.hashCode ^ functionValue.hashCode ^ delaySeconds.hashCode;
}

View File

@ -1,46 +1,54 @@
import 'dart:convert';
class SceneModel {
final String id;
final String name;
final String description;
final String imageUrl;
final String location;
final String type;
final String rating;
final String price;
final String duration;
final String date;
final String time;
final String status;
final Status status;
final Type type;
SceneModel({
required this.id,
required this.name,
required this.description,
required this.imageUrl,
required this.location,
required this.type,
required this.rating,
required this.price,
required this.duration,
required this.date,
required this.time,
required this.status,
required this.type,
});
factory SceneModel.fromJson(Map<String, dynamic> json) {
return SceneModel(
id: json['id'],
name: json['name'],
description: json['description'],
imageUrl: json['imageUrl'],
location: json['location'],
type: json['type'],
rating: json['rating'],
price: json['price'],
duration: json['duration'],
date: json['date'],
time: json['time'],
status: json['status'],
);
factory SceneModel.fromRawJson(String str) =>
SceneModel.fromJson(json.decode(str));
String toRawJson() => json.encode(toJson());
factory SceneModel.fromJson(Map<String, dynamic> json) => SceneModel(
id: json["id"],
name: json["name"],
status: statusValues.map[json["status"]]!,
type: typeValues.map[json["type"]]!,
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"status": statusValues.reverse[status],
"type": typeValues.reverse[type],
};
}
enum Status { ENABLE }
final statusValues = EnumValues({"enable": Status.ENABLE});
enum Type { TAP_TO_RUN }
final typeValues = EnumValues({"tap_to_run": Type.TAP_TO_RUN});
class EnumValues<T> {
Map<String, T> map;
late Map<T, String> reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
reverseMap = map.map((k, v) => MapEntry(v, k));
return reverseMap;
}
}

View File

@ -99,34 +99,36 @@ class SceneStaticFunction {
class SceneOperationalValue {
final String icon;
final String value;
final dynamic value;
final String? description;
SceneOperationalValue({
required this.icon,
required this.value,
this.description,
});
SceneOperationalValue copyWith({
String? icon,
String? value,
dynamic value,
String? description,
}) {
return SceneOperationalValue(
icon: icon ?? this.icon,
value: value ?? this.value,
description: description ?? this.description,
);
}
Map<String, dynamic> toMap() {
return {
'icon': icon,
'value': value,
};
return {'icon': icon, 'value': value, 'description': description};
}
factory SceneOperationalValue.fromMap(Map<String, dynamic> map) {
return SceneOperationalValue(
icon: map['icon'] ?? '',
value: map['value'] ?? '',
value: map['value'],
description: map['description'],
);
}
@ -137,7 +139,7 @@ class SceneOperationalValue {
@override
String toString() =>
'StaticFunctionOperationHelper(icon: $icon, value: $value)';
'StaticFunctionOperationHelper(icon: $icon, value: $value, description: $description)';
@override
bool operator ==(Object other) {
@ -145,9 +147,10 @@ class SceneOperationalValue {
return other is SceneOperationalValue &&
other.icon == icon &&
other.description == description &&
other.value == value;
}
@override
int get hashCode => icon.hashCode ^ value.hashCode;
int get hashCode => icon.hashCode ^ value.hashCode ^ description.hashCode;
}