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:
@@ -1,3 +1,9 @@
|
|||||||
|
## Upcoming
|
||||||
|
|
||||||
|
🐞 Fixed
|
||||||
|
|
||||||
|
- Do not serialize `AttachmentFile.bytes`
|
||||||
|
|
||||||
## 4.4.0
|
## 4.4.0
|
||||||
|
|
||||||
🐞 Fixed
|
🐞 Fixed
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class AttachmentFile {
|
|||||||
|
|
||||||
/// Byte data for this file. Particularly useful if you want to manipulate
|
/// Byte data for this file. Particularly useful if you want to manipulate
|
||||||
/// its data or easily upload to somewhere else.
|
/// its data or easily upload to somewhere else.
|
||||||
@JsonKey(toJson: _toString, fromJson: _fromString)
|
@JsonKey(ignore: true)
|
||||||
final Uint8List? bytes;
|
final Uint8List? bytes;
|
||||||
|
|
||||||
/// The file size in bytes.
|
/// The file size in bytes.
|
||||||
@@ -124,13 +124,3 @@ class UploadState with _$UploadState {
|
|||||||
/// Returns true if state is [Failed]
|
/// Returns true if state is [Failed]
|
||||||
bool get isFailed => this 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
|
@override
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return _$$PreparingToJson(this);
|
return _$$PreparingToJson(
|
||||||
|
this,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,7 +394,9 @@ class _$InProgress extends InProgress {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, dynamic> toJson() {
|
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) =
|
factory InProgress.fromJson(Map<String, dynamic> json) =
|
||||||
_$InProgress.fromJson;
|
_$InProgress.fromJson;
|
||||||
|
|
||||||
int get uploaded => throw _privateConstructorUsedError;
|
int get uploaded;
|
||||||
int get total => throw _privateConstructorUsedError;
|
int get total;
|
||||||
@JsonKey(ignore: true)
|
@JsonKey(ignore: true)
|
||||||
_$$InProgressCopyWith<_$InProgress> get copyWith =>
|
_$$InProgressCopyWith<_$InProgress> get copyWith =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
@@ -531,7 +535,9 @@ class _$Success extends Success {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return _$$SuccessToJson(this);
|
return _$$SuccessToJson(
|
||||||
|
this,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,7 +692,9 @@ class _$Failed extends Failed {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, dynamic> toJson() {
|
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;
|
factory Failed.fromJson(Map<String, dynamic> json) = _$Failed.fromJson;
|
||||||
|
|
||||||
String get error => throw _privateConstructorUsedError;
|
String get error;
|
||||||
@JsonKey(ignore: true)
|
@JsonKey(ignore: true)
|
||||||
_$$FailedCopyWith<_$Failed> get copyWith =>
|
_$$FailedCopyWith<_$Failed> get copyWith =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
|
|||||||
@@ -11,14 +11,12 @@ AttachmentFile _$AttachmentFileFromJson(Map<String, dynamic> json) =>
|
|||||||
size: json['size'] as int?,
|
size: json['size'] as int?,
|
||||||
path: json['path'] as String?,
|
path: json['path'] as String?,
|
||||||
name: json['name'] as String?,
|
name: json['name'] as String?,
|
||||||
bytes: _fromString(json['bytes'] as String?),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> _$AttachmentFileToJson(AttachmentFile instance) =>
|
Map<String, dynamic> _$AttachmentFileToJson(AttachmentFile instance) =>
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
'path': instance.path,
|
'path': instance.path,
|
||||||
'name': instance.name,
|
'name': instance.name,
|
||||||
'bytes': _toString(instance.bytes),
|
|
||||||
'size': instance.size,
|
'size': instance.size,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+10
-7
@@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:photo_manager/photo_manager.dart';
|
import 'package:photo_manager/photo_manager.dart';
|
||||||
import 'package:stream_chat_flutter/src/extension.dart';
|
import 'package:stream_chat_flutter/src/extension.dart';
|
||||||
import 'package:stream_chat_flutter/src/media_list_view.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 {
|
void _addAssetAttachment(AssetEntity medium) async {
|
||||||
final mediaFile = await medium.originFile.timeout(
|
final mediaFile = await medium.originFile;
|
||||||
const Duration(seconds: 5),
|
|
||||||
onTimeout: () => medium.originFile,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (mediaFile == null) return;
|
if (mediaFile == null) return;
|
||||||
|
|
||||||
|
final tempDir = await getTemporaryDirectory();
|
||||||
|
|
||||||
|
final cachedFile = await mediaFile
|
||||||
|
.copy('${tempDir.path}/${mediaFile.path.split('/').last}');
|
||||||
|
|
||||||
final file = AttachmentFile(
|
final file = AttachmentFile(
|
||||||
path: mediaFile.path,
|
path: cachedFile.path,
|
||||||
size: await mediaFile.length(),
|
size: await cachedFile.length(),
|
||||||
bytes: mediaFile.readAsBytesSync(),
|
bytes: cachedFile.readAsBytesSync(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (file.size! > widget.maxAttachmentSize) {
|
if (file.size! > widget.maxAttachmentSize) {
|
||||||
|
|||||||
Reference in New Issue
Block a user