68 lines
1.7 KiB
Dart
68 lines
1.7 KiB
Dart
import 'dart:convert';
|
|
import 'dart:typed_data' show Uint8List;
|
|
|
|
class FFUploadedFile {
|
|
const FFUploadedFile({
|
|
this.name,
|
|
this.bytes,
|
|
this.height,
|
|
this.width,
|
|
this.blurHash,
|
|
});
|
|
|
|
final String? name;
|
|
final Uint8List? bytes;
|
|
final double? height;
|
|
final double? width;
|
|
final String? blurHash;
|
|
|
|
@override
|
|
String toString() =>
|
|
'FFUploadedFile(name: $name, bytes: ${bytes?.length ?? 0}, height: $height, width: $width, blurHash: $blurHash,)';
|
|
|
|
String serialize() => jsonEncode(
|
|
{
|
|
'name': name,
|
|
'bytes': bytes,
|
|
'height': height,
|
|
'width': width,
|
|
'blurHash': blurHash,
|
|
},
|
|
);
|
|
|
|
static FFUploadedFile deserialize(String val) {
|
|
final serializedData = jsonDecode(val) as Map<String, dynamic>;
|
|
final data = {
|
|
'name': serializedData['name'] ?? '',
|
|
'bytes': serializedData['bytes'] ?? Uint8List.fromList([]),
|
|
'height': serializedData['height'],
|
|
'width': serializedData['width'],
|
|
'blurHash': serializedData['blurHash'],
|
|
};
|
|
return FFUploadedFile(
|
|
name: data['name'] as String,
|
|
bytes: Uint8List.fromList(data['bytes'].cast<int>().toList()),
|
|
height: data['height'] as double?,
|
|
width: data['width'] as double?,
|
|
blurHash: data['blurHash'] as String?,
|
|
);
|
|
}
|
|
|
|
@override
|
|
int get hashCode => Object.hash(
|
|
name,
|
|
bytes,
|
|
height,
|
|
width,
|
|
blurHash,
|
|
);
|
|
|
|
@override
|
|
bool operator ==(other) =>
|
|
other is FFUploadedFile &&
|
|
name == other.name &&
|
|
bytes == other.bytes &&
|
|
height == other.height &&
|
|
width == other.width &&
|
|
blurHash == other.blurHash;
|
|
} |