Skip to content

Instantly share code, notes, and snippets.

@FlutterWiz
Created January 7, 2023 16:42
Show Gist options
  • Save FlutterWiz/9d12eac6bdbec47147483e5f824df1a9 to your computer and use it in GitHub Desktop.
Save FlutterWiz/9d12eac6bdbec47147483e5f824df1a9 to your computer and use it in GitHub Desktop.
@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