2022-02-11 03:40:11 +01:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2022-04-02 19:31:53 +02:00
|
|
|
enum DownloadAssetStatus { idle, loading, success, error }
|
|
|
|
|
2024-05-01 04:36:40 +02:00
|
|
|
class AssetViewerPageState {
|
2022-04-02 19:31:53 +02:00
|
|
|
// enum
|
|
|
|
final DownloadAssetStatus downloadAssetStatus;
|
|
|
|
|
2024-05-01 04:36:40 +02:00
|
|
|
AssetViewerPageState({
|
2022-04-02 19:31:53 +02:00
|
|
|
required this.downloadAssetStatus,
|
2022-02-11 03:40:11 +01:00
|
|
|
});
|
|
|
|
|
2024-05-01 04:36:40 +02:00
|
|
|
AssetViewerPageState copyWith({
|
2022-04-02 19:31:53 +02:00
|
|
|
DownloadAssetStatus? downloadAssetStatus,
|
2022-02-11 03:40:11 +01:00
|
|
|
}) {
|
2024-05-01 04:36:40 +02:00
|
|
|
return AssetViewerPageState(
|
2022-04-02 19:31:53 +02:00
|
|
|
downloadAssetStatus: downloadAssetStatus ?? this.downloadAssetStatus,
|
2022-02-11 03:40:11 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
2022-04-02 19:31:53 +02:00
|
|
|
final result = <String, dynamic>{};
|
|
|
|
|
|
|
|
result.addAll({'downloadAssetStatus': downloadAssetStatus.index});
|
|
|
|
|
|
|
|
return result;
|
2022-02-11 03:40:11 +01:00
|
|
|
}
|
|
|
|
|
2024-05-01 04:36:40 +02:00
|
|
|
factory AssetViewerPageState.fromMap(Map<String, dynamic> map) {
|
|
|
|
return AssetViewerPageState(
|
2022-06-25 22:12:47 +02:00
|
|
|
downloadAssetStatus:
|
|
|
|
DownloadAssetStatus.values[map['downloadAssetStatus'] ?? 0],
|
2022-02-11 03:40:11 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
|
2024-05-01 04:36:40 +02:00
|
|
|
factory AssetViewerPageState.fromJson(String source) =>
|
|
|
|
AssetViewerPageState.fromMap(json.decode(source));
|
2022-02-11 03:40:11 +01:00
|
|
|
|
|
|
|
@override
|
2022-06-25 22:12:47 +02:00
|
|
|
String toString() =>
|
|
|
|
'ImageViewerPageState(downloadAssetStatus: $downloadAssetStatus)';
|
2022-02-11 03:40:11 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) {
|
|
|
|
if (identical(this, other)) return true;
|
|
|
|
|
2024-05-01 04:36:40 +02:00
|
|
|
return other is AssetViewerPageState &&
|
2022-06-25 22:12:47 +02:00
|
|
|
other.downloadAssetStatus == downloadAssetStatus;
|
2022-02-11 03:40:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-04-02 19:31:53 +02:00
|
|
|
int get hashCode => downloadAssetStatus.hashCode;
|
2022-02-11 03:40:11 +01:00
|
|
|
}
|