Created
January 7, 2023 16:42
-
-
Save FlutterWiz/9d12eac6bdbec47147483e5f824df1a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
Future<void> sendPhotoAsMessageToTheSelectedUser({ | |
required String channelId, | |
required int sizeOfTheTakenPhoto, | |
required String pathOfTheTakenPhoto, | |
}) async { | |
final randomMessageId = const Uuid().v1(); | |
final signedInUserOption = await _firebaseAuth.getSignedInUser(); | |
final signedInUser = signedInUserOption.fold( | |
() => throw Exception("Not authanticated"), | |
(user) => user, | |
); | |
final user = User(id: signedInUser.id); | |
streamChatClient | |
.sendImage( | |
AttachmentFile( | |
size: sizeOfTheTakenPhoto, | |
path: pathOfTheTakenPhoto, | |
), | |
channelId, | |
"messaging", | |
) | |
.then((response) { | |
// Successful upload, you can now attach this image | |
// to an message that you then send to a channel | |
final imageUrl = response.file; | |
final image = Attachment( | |
type: 'image', | |
imageUrl: imageUrl, | |
); | |
final message = Message( | |
user: user, | |
id: randomMessageId, | |
createdAt: DateTime.now(), | |
attachments: [image], | |
); | |
streamChatClient.sendMessage(message, channelId, "messaging"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment