mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-18 18:33:49 +02:00
feat(chat-service/pending-messages): add pending images
This commit is contained in:
parent
d52b558794
commit
18b4a8fc32
6 changed files with 36 additions and 3 deletions
|
@ -0,0 +1,25 @@
|
|||
import "dart:convert";
|
||||
import "dart:typed_data";
|
||||
import "package:mime/mime.dart";
|
||||
|
||||
/// Error thrown when there is no
|
||||
/// mimetype found
|
||||
class MimetypeMissingError extends Error {
|
||||
@override
|
||||
String toString() => "You can only provide files that contain a mimetype";
|
||||
}
|
||||
|
||||
/// Extension that provides a converter function from
|
||||
/// Uin8List to a base64Encoded data uri.
|
||||
extension ToDataUri on Uint8List {
|
||||
/// This function converts the Uint8List into
|
||||
/// a uri with a data-scheme.
|
||||
String toDataUri() {
|
||||
var mimeType = lookupMimeType("", headerBytes: this);
|
||||
if (mimeType == null) throw MimetypeMissingError();
|
||||
|
||||
var base64Data = base64Encode(this);
|
||||
|
||||
return "data:$mimeType;base64,$base64Data";
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ import "dart:math" as math;
|
|||
import "dart:typed_data";
|
||||
|
||||
import "package:chat_repository_interface/chat_repository_interface.dart";
|
||||
import "package:chat_repository_interface/src/extension/uint8list_data_uri.dart";
|
||||
import "package:chat_repository_interface/src/local/local_memory_db.dart";
|
||||
import "package:collection/collection.dart";
|
||||
import "package:rxdart/rxdart.dart";
|
||||
|
@ -272,7 +273,7 @@ class LocalChatRepository implements ChatRepositoryInterface {
|
|||
required String chatId,
|
||||
required String senderId,
|
||||
}) =>
|
||||
Future.value("https://picsum.photos/200/300");
|
||||
Future.value(image.toDataUri());
|
||||
|
||||
/// All the chats of the local memory database
|
||||
List<ChatModel> get getLocalChats => chats;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import "dart:async";
|
||||
import "dart:typed_data";
|
||||
|
||||
import "package:chat_repository_interface/src/extension/uint8list_data_uri.dart";
|
||||
import "package:chat_repository_interface/src/interfaces/chat_repostory_interface.dart";
|
||||
import "package:chat_repository_interface/src/interfaces/pending_message_repository_interface.dart";
|
||||
import "package:chat_repository_interface/src/interfaces/user_repository_interface.dart";
|
||||
|
@ -203,6 +204,7 @@ class ChatService {
|
|||
String? text,
|
||||
String? messageType,
|
||||
String? imageUrl,
|
||||
Uint8List? imageData,
|
||||
}) async {
|
||||
await pendingMessageRepository.createMessage(
|
||||
chatId: chatId,
|
||||
|
@ -210,7 +212,7 @@ class ChatService {
|
|||
messageId: messageId,
|
||||
text: text,
|
||||
messageType: messageType,
|
||||
imageUrl: imageUrl,
|
||||
imageUrl: imageData?.toDataUri() ?? imageUrl,
|
||||
);
|
||||
|
||||
unawaited(
|
||||
|
|
|
@ -9,6 +9,7 @@ environment:
|
|||
sdk: ">=3.4.3 <4.0.0"
|
||||
|
||||
dependencies:
|
||||
mime: any
|
||||
rxdart: any
|
||||
collection: any
|
||||
|
||||
|
|
|
@ -284,7 +284,10 @@ ImageProvider _defaultImageProviderResolver(
|
|||
BuildContext context,
|
||||
Uri image,
|
||||
) =>
|
||||
CachedNetworkImageProvider(image.toString());
|
||||
switch (image.scheme) {
|
||||
"data" => MemoryImage(image.data!.contentAsBytes()),
|
||||
_ => CachedNetworkImageProvider(image.toString()),
|
||||
};
|
||||
|
||||
/// All configurable paddings and whitespaces within the userstory
|
||||
class ChatSpacing {
|
||||
|
|
|
@ -61,6 +61,7 @@ MaterialPageRoute chatDetailRoute({
|
|||
chatId: chatId,
|
||||
senderId: userId,
|
||||
imageUrl: path,
|
||||
imageData: data,
|
||||
);
|
||||
},
|
||||
onMessageSubmit: (text) async {
|
||||
|
|
Loading…
Reference in a new issue