Skip to main content

create single chat

    try {
//create your desgin
final res =
await CustomAlert.chatAlert(context: context, peerEmail: email);
if (res != null) {
await VChatController.instance
.createSingleChat(peerEmail: email, message: res, context: context);
CustomAlert.done(
msg: "Message has been sent successfully",
);
}
} on VChatSdkException catch (err) {
CustomAlert.showError(context: context, err: err.toString());
rethrow;
}

you can create alert dialog to get first message from user like this

   showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("new message"),
content: TextField(
onChanged: (value) {
txt = value;
},
),
actions: [
TextButton(
onPressed: ()async {
await VChatController.instance
.createSingleChat(
peerEmail: "peerEmail",
message: txt,
context: context);
},
child: Text("send"))
],
);
},
);
  • peerEmail => is the unique identifier that you pass to vchat when register this function throw
  • message => first message is required and must not be empty ("") or null
  • context => if you pass the context the chat page will open directly after message send other message will send only
  1. you can't start chat if you start chat your self
  2. Exception if peer Email Not in v chat Database ! so first you must (migrate all users only if already in production and need to add chat) new project all will be fine
  3. No internet connection
  4. Example