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