mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-15 01:35:25 +00:00
add the delete api
This commit is contained in:
@ -0,0 +1,93 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||
|
||||
/*
|
||||
{
|
||||
"category": "kg",
|
||||
"time": "2024-09-22T10:31:54Z",
|
||||
"function": {
|
||||
"code": "switch_1",
|
||||
"value": true
|
||||
},
|
||||
"days": [
|
||||
"Sun"
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
class ScheduleModel {
|
||||
final String category;
|
||||
final String time;
|
||||
final Status function;
|
||||
final List<String> days;
|
||||
|
||||
ScheduleModel({
|
||||
required this.category,
|
||||
required this.time,
|
||||
required this.function,
|
||||
required this.days,
|
||||
});
|
||||
|
||||
ScheduleModel copyWith({
|
||||
String? category,
|
||||
String? time,
|
||||
Status? function,
|
||||
List<String>? days,
|
||||
}) {
|
||||
return ScheduleModel(
|
||||
category: category ?? this.category,
|
||||
time: time ?? this.time,
|
||||
function: function ?? this.function,
|
||||
days: days ?? this.days,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'category': category,
|
||||
'time': time,
|
||||
'function': function.toMap(),
|
||||
'days': days,
|
||||
};
|
||||
}
|
||||
|
||||
factory ScheduleModel.fromMap(Map<String, dynamic> map) {
|
||||
return ScheduleModel(
|
||||
category: map['category'] ?? '',
|
||||
time: map['time'] ?? '',
|
||||
function: Status.fromMap(map['function']),
|
||||
days: List<String>.from(map['days']),
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory ScheduleModel.fromJson(String source) =>
|
||||
ScheduleModel.fromMap(json.decode(source));
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SendSchedule(category: $category, time: $time, function: $function, days: $days)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is ScheduleModel &&
|
||||
other.category == category &&
|
||||
other.time == time &&
|
||||
other.function == function &&
|
||||
listEquals(other.days, days);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return category.hashCode ^
|
||||
time.hashCode ^
|
||||
function.hashCode ^
|
||||
days.hashCode;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user