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
84cc630c6e
commit
3fbcf5d076
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 "dart:typed_data";
|
||||||
|
|
||||||
import "package:chat_repository_interface/chat_repository_interface.dart";
|
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:chat_repository_interface/src/local/local_memory_db.dart";
|
||||||
import "package:collection/collection.dart";
|
import "package:collection/collection.dart";
|
||||||
import "package:rxdart/rxdart.dart";
|
import "package:rxdart/rxdart.dart";
|
||||||
|
@ -272,7 +273,7 @@ class LocalChatRepository implements ChatRepositoryInterface {
|
||||||
required String chatId,
|
required String chatId,
|
||||||
required String senderId,
|
required String senderId,
|
||||||
}) =>
|
}) =>
|
||||||
Future.value("https://picsum.photos/200/300");
|
Future.value(image.toDataUri());
|
||||||
|
|
||||||
/// All the chats of the local memory database
|
/// All the chats of the local memory database
|
||||||
List<ChatModel> get getLocalChats => chats;
|
List<ChatModel> get getLocalChats => chats;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import "dart:async";
|
import "dart:async";
|
||||||
import "dart:typed_data";
|
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/chat_repostory_interface.dart";
|
||||||
import "package:chat_repository_interface/src/interfaces/pending_message_repository_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";
|
import "package:chat_repository_interface/src/interfaces/user_repository_interface.dart";
|
||||||
|
@ -203,6 +204,7 @@ class ChatService {
|
||||||
String? text,
|
String? text,
|
||||||
String? messageType,
|
String? messageType,
|
||||||
String? imageUrl,
|
String? imageUrl,
|
||||||
|
Uint8List? imageData,
|
||||||
}) async {
|
}) async {
|
||||||
await pendingMessageRepository.createMessage(
|
await pendingMessageRepository.createMessage(
|
||||||
chatId: chatId,
|
chatId: chatId,
|
||||||
|
@ -210,7 +212,7 @@ class ChatService {
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
text: text,
|
text: text,
|
||||||
messageType: messageType,
|
messageType: messageType,
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageData?.toDataUri() ?? imageUrl,
|
||||||
);
|
);
|
||||||
|
|
||||||
unawaited(
|
unawaited(
|
||||||
|
|
|
@ -9,6 +9,7 @@ environment:
|
||||||
sdk: ">=3.4.3 <4.0.0"
|
sdk: ">=3.4.3 <4.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
mime: any
|
||||||
rxdart: any
|
rxdart: any
|
||||||
collection: any
|
collection: any
|
||||||
|
|
||||||
|
|
|
@ -284,7 +284,10 @@ ImageProvider _defaultImageProviderResolver(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Uri image,
|
Uri image,
|
||||||
) =>
|
) =>
|
||||||
CachedNetworkImageProvider(image.toString());
|
switch (image.scheme) {
|
||||||
|
"data" => MemoryImage(image.data!.contentAsBytes()),
|
||||||
|
_ => CachedNetworkImageProvider(image.toString()),
|
||||||
|
};
|
||||||
|
|
||||||
/// All configurable paddings and whitespaces within the userstory
|
/// All configurable paddings and whitespaces within the userstory
|
||||||
class ChatSpacing {
|
class ChatSpacing {
|
||||||
|
|
|
@ -61,6 +61,7 @@ MaterialPageRoute chatDetailRoute({
|
||||||
chatId: chatId,
|
chatId: chatId,
|
||||||
senderId: userId,
|
senderId: userId,
|
||||||
imageUrl: path,
|
imageUrl: path,
|
||||||
|
imageData: data,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
onMessageSubmit: (text) async {
|
onMessageSubmit: (text) async {
|
||||||
|
|
Loading…
Reference in a new issue