@@ -3,9 +3,13 @@ import 'package:stream_chat/src/models/attachment_file.dart';
|
||||
import '../client.dart';
|
||||
import '../extensions/string_extension.dart';
|
||||
|
||||
///
|
||||
/// Class responsible for uploading images and files from a given channel
|
||||
abstract class AttachmentUploader {
|
||||
/// Uploads a image [file] to the given channel.
|
||||
/// Returns image [file] URL once sent successfully.
|
||||
///
|
||||
/// Optionally, access upload progress using [onSendProgress]
|
||||
/// and cancel the request using [cancelToken]
|
||||
Future<String> uploadImage(
|
||||
AttachmentFile file,
|
||||
String channelId,
|
||||
@@ -14,7 +18,11 @@ abstract class AttachmentUploader {
|
||||
CancelToken cancelToken,
|
||||
});
|
||||
|
||||
/// Uploads a [file] to the given channel.
|
||||
/// Returns [file] URL once sent successfully.
|
||||
///
|
||||
/// Optionally, access upload progress using [onSendProgress]
|
||||
/// and cancel the request using [cancelToken]
|
||||
Future<String> uploadFile(
|
||||
AttachmentFile file,
|
||||
String channelId,
|
||||
@@ -24,11 +32,11 @@ abstract class AttachmentUploader {
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
/// Stream's default implementation of [AttachmentUploader]
|
||||
class StreamAttachmentUploader implements AttachmentUploader {
|
||||
final StreamChatClient _client;
|
||||
|
||||
///
|
||||
/// Creates a new [StreamAttachmentUploader] instance.
|
||||
const StreamAttachmentUploader(this._client);
|
||||
|
||||
@override
|
||||
|
||||
@@ -7,16 +7,16 @@ part 'attachment_file.freezed.dart';
|
||||
|
||||
part 'attachment_file.g.dart';
|
||||
|
||||
///
|
||||
/// Union class to hold various [UploadState] of a attachment.
|
||||
@freezed
|
||||
abstract class UploadState with _$UploadState {
|
||||
///
|
||||
/// InProgress state of the union
|
||||
const factory UploadState.inProgress({int uploaded, int total}) = InProgress;
|
||||
|
||||
///
|
||||
/// Success state of the union
|
||||
const factory UploadState.success() = Success;
|
||||
|
||||
///
|
||||
/// Failed state of the union
|
||||
const factory UploadState.failed({@required String error}) = Failed;
|
||||
|
||||
/// Creates a new instance from a json
|
||||
@@ -24,15 +24,15 @@ abstract class UploadState with _$UploadState {
|
||||
_$UploadStateFromJson(json);
|
||||
}
|
||||
|
||||
///
|
||||
/// Helper extension for UploadState
|
||||
extension UploadStateX on UploadState {
|
||||
///
|
||||
/// Returns true if state is [InProgress]
|
||||
bool get isInProgress => this is InProgress;
|
||||
|
||||
///
|
||||
/// Returns true if state is [Success]
|
||||
bool get isSuccess => this is Success;
|
||||
|
||||
///
|
||||
/// Returns true if state is [Failed]
|
||||
bool get isFailed => this is Failed;
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ Uint8List _fromString(String bytes) => Uint8List.fromList(bytes.codeUnits);
|
||||
|
||||
String _toString(Uint8List bytes) => String.fromCharCodes(bytes);
|
||||
|
||||
///
|
||||
/// The class that contains the information about an attachment file
|
||||
@JsonSerializable()
|
||||
class AttachmentFile {
|
||||
///
|
||||
/// Creates a new [AttachmentFile] instance.
|
||||
const AttachmentFile({
|
||||
this.path,
|
||||
this.name,
|
||||
|
||||
@@ -34,9 +34,9 @@ extension IterableX<T> on Iterable<T> {
|
||||
}).skip(1).toList(growable: false);
|
||||
}
|
||||
|
||||
///
|
||||
/// Useful extension for [PlatformFile]
|
||||
extension PlatformFileX on PlatformFile {
|
||||
///
|
||||
/// Converts the [PlatformFile] into [AttachmentFile]
|
||||
AttachmentFile get toAttachmentFile => AttachmentFile(
|
||||
path: path,
|
||||
name: name,
|
||||
|
||||
Reference in New Issue
Block a user