ente/lib/models/folder.dart

78 lines
1.7 KiB
Dart
Raw Normal View History

2020-05-17 20:39:21 +00:00
import 'dart:convert';
import 'package:flutter/foundation.dart';
2020-05-17 12:39:38 +00:00
class Folder {
2020-05-17 20:39:21 +00:00
final int id;
2020-05-17 12:39:38 +00:00
final String name;
final String owner;
final String deviceFolder;
final List<String> sharedWith;
final int updateTimestamp;
2020-05-17 19:35:57 +00:00
Folder(
2020-05-17 20:39:21 +00:00
this.id,
2020-05-17 19:35:57 +00:00
this.name,
this.owner,
this.deviceFolder,
this.sharedWith,
this.updateTimestamp,
);
static Folder fromMap(Map<String, dynamic> map) {
if (map == null) return null;
return Folder(
2020-05-17 20:39:21 +00:00
map['id'],
2020-05-17 19:35:57 +00:00
map['name'],
map['owner'],
map['deviceFolder'],
List<String>.from(map['sharedWith']),
map['updateTimestamp'],
);
}
@override
String toString() {
2020-05-17 20:39:21 +00:00
return 'Folder(id: $id, name: $name, owner: $owner, deviceFolder: $deviceFolder, sharedWith: $sharedWith, updateTimestamp: $updateTimestamp)';
}
Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
'owner': owner,
'deviceFolder': deviceFolder,
'sharedWith': sharedWith,
'updateTimestamp': updateTimestamp,
};
}
String toJson() => json.encode(toMap());
static Folder fromJson(String source) => fromMap(json.decode(source));
@override
bool operator ==(Object o) {
if (identical(this, o)) return true;
return o is Folder &&
o.id == id &&
o.name == name &&
o.owner == owner &&
o.deviceFolder == deviceFolder &&
listEquals(o.sharedWith, sharedWith) &&
o.updateTimestamp == updateTimestamp;
}
@override
int get hashCode {
return id.hashCode ^
name.hashCode ^
owner.hashCode ^
deviceFolder.hashCode ^
sharedWith.hashCode ^
updateTimestamp.hashCode;
2020-05-17 19:35:57 +00:00
}
2020-05-17 12:39:38 +00:00
}