fix(llc): do not serialize bytes (#1283)

* fix(llc): do not serialize bytes

* chore(llc): update changelog

* fix(ui): cache files picked with photo_manager

* chore(ui): cleanup
This commit is contained in:
Salvatore Giordano
2022-07-27 10:36:11 +02:00
committed by GitHub
parent e9e35d7d29
commit 89e160969d
5 changed files with 32 additions and 27 deletions
+6
View File
@@ -1,3 +1,9 @@
## Upcoming
🐞 Fixed
- Do not serialize `AttachmentFile.bytes`
## 4.4.0
🐞 Fixed
@@ -51,7 +51,7 @@ class AttachmentFile {
/// Byte data for this file. Particularly useful if you want to manipulate
/// its data or easily upload to somewhere else.
@JsonKey(toJson: _toString, fromJson: _fromString)
@JsonKey(ignore: true)
final Uint8List? bytes;
/// The file size in bytes.
@@ -124,13 +124,3 @@ class UploadState with _$UploadState {
/// Returns true if state is [Failed]
bool get isFailed => this is Failed;
}
Uint8List? _fromString(String? bytes) {
if (bytes == null) return null;
return Uint8List.fromList(bytes.codeUnits);
}
String? _toString(Uint8List? bytes) {
if (bytes == null) return null;
return String.fromCharCodes(bytes);
}
@@ -224,7 +224,9 @@ class _$Preparing extends Preparing {
@override
Map<String, dynamic> toJson() {
return _$$PreparingToJson(this);
return _$$PreparingToJson(
this,
);
}
}
@@ -392,7 +394,9 @@ class _$InProgress extends InProgress {
@override
Map<String, dynamic> toJson() {
return _$$InProgressToJson(this);
return _$$InProgressToJson(
this,
);
}
}
@@ -404,8 +408,8 @@ abstract class InProgress extends UploadState {
factory InProgress.fromJson(Map<String, dynamic> json) =
_$InProgress.fromJson;
int get uploaded => throw _privateConstructorUsedError;
int get total => throw _privateConstructorUsedError;
int get uploaded;
int get total;
@JsonKey(ignore: true)
_$$InProgressCopyWith<_$InProgress> get copyWith =>
throw _privateConstructorUsedError;
@@ -531,7 +535,9 @@ class _$Success extends Success {
@override
Map<String, dynamic> toJson() {
return _$$SuccessToJson(this);
return _$$SuccessToJson(
this,
);
}
}
@@ -686,7 +692,9 @@ class _$Failed extends Failed {
@override
Map<String, dynamic> toJson() {
return _$$FailedToJson(this);
return _$$FailedToJson(
this,
);
}
}
@@ -696,7 +704,7 @@ abstract class Failed extends UploadState {
factory Failed.fromJson(Map<String, dynamic> json) = _$Failed.fromJson;
String get error => throw _privateConstructorUsedError;
String get error;
@JsonKey(ignore: true)
_$$FailedCopyWith<_$Failed> get copyWith =>
throw _privateConstructorUsedError;
@@ -11,14 +11,12 @@ AttachmentFile _$AttachmentFileFromJson(Map<String, dynamic> json) =>
size: json['size'] as int?,
path: json['path'] as String?,
name: json['name'] as String?,
bytes: _fromString(json['bytes'] as String?),
);
Map<String, dynamic> _$AttachmentFileToJson(AttachmentFile instance) =>
<String, dynamic>{
'path': instance.path,
'name': instance.name,
'bytes': _toString(instance.bytes),
'size': instance.size,
};
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:path_provider/path_provider.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:stream_chat_flutter/src/extension.dart';
import 'package:stream_chat_flutter/src/media_list_view.dart';
@@ -369,17 +370,19 @@ class _StreamAttachmentPickerState extends State<StreamAttachmentPicker> {
}
void _addAssetAttachment(AssetEntity medium) async {
final mediaFile = await medium.originFile.timeout(
const Duration(seconds: 5),
onTimeout: () => medium.originFile,
);
final mediaFile = await medium.originFile;
if (mediaFile == null) return;
final tempDir = await getTemporaryDirectory();
final cachedFile = await mediaFile
.copy('${tempDir.path}/${mediaFile.path.split('/').last}');
final file = AttachmentFile(
path: mediaFile.path,
size: await mediaFile.length(),
bytes: mediaFile.readAsBytesSync(),
path: cachedFile.path,
size: await cachedFile.length(),
bytes: cachedFile.readAsBytesSync(),
);
if (file.size! > widget.maxAttachmentSize) {