From 3ad22b16b360f12a160f357f7adbaf83b8107af6 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 17 Feb 2021 18:27:58 +0530 Subject: [PATCH] Add docs Signed-off-by: Sahil Kumar --- .../lib/src/api/attachment_uploader.dart | 14 ++++++++++--- .../lib/src/models/attachment_file.dart | 20 +++++++++---------- .../lib/src/extension.dart | 4 ++-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/packages/stream_chat/lib/src/api/attachment_uploader.dart b/packages/stream_chat/lib/src/api/attachment_uploader.dart index c4c87dcb..a5d2d576 100644 --- a/packages/stream_chat/lib/src/api/attachment_uploader.dart +++ b/packages/stream_chat/lib/src/api/attachment_uploader.dart @@ -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 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 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 diff --git a/packages/stream_chat/lib/src/models/attachment_file.dart b/packages/stream_chat/lib/src/models/attachment_file.dart index bffc24ae..d7a1ba88 100644 --- a/packages/stream_chat/lib/src/models/attachment_file.dart +++ b/packages/stream_chat/lib/src/models/attachment_file.dart @@ -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, diff --git a/packages/stream_chat_flutter/lib/src/extension.dart b/packages/stream_chat_flutter/lib/src/extension.dart index af2b0994..f19d851b 100644 --- a/packages/stream_chat_flutter/lib/src/extension.dart +++ b/packages/stream_chat_flutter/lib/src/extension.dart @@ -34,9 +34,9 @@ extension IterableX on Iterable { }).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,