I'm trying to create a chat screen in my flutter application using Stream chat API
. the problem is when I try to create a channel with two users it shows that the users are not created even though I have created them:
E/flutter ( 4695): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception:
StreamChatNetworkError(code: 4, message: GetOrCreateChannel failed with error: "The following
users are involved in channel create operation, but don't exist: [hasan11 mohammed11]. Please
create the user objects before setting up the channel.", statusCode: 400, data:
ErrorResponse(code: 4, message: GetOrCreateChannel failed with error: "The following users are
involved in channel create operation, but don't exist: [hasan11 mohammed11]. Please create the
user objects before setting up the channel.", statusCode: 400, moreInfo:
https://getstream.io/chat/docs/api_errors_response))
here is my dart code for initializing the channel and the users:
onPressed () {
await streamAPI.initUser(client,
username: 'hasan',
id: Config.hasanID,
token: Config.hasanToken);
final channel = await streamAPI.createChannel(
client, 'messaging', 'sample', [Config.hasanID, Config.mohammedID]);
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
chat(client: client, channel: channel)));
}
StreamAPI.dart code:
import 'package:flutter/cupertino.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
class streamAPI {
static Future initUser(
StreamChatClient client, {
@required String username,
@required String id,
@required String token
}) async {
final user = User(
id: id,
extraData: {
'name': username
}
);
await client.connectUser(user, token);
}
static Future<Channel> createChannel(
StreamChatClient client,
@required String type,
@required String id,
List<String> idMembers
) async {
final channel = client.channel(type, id: id, extraData: {
'name': 'channel1',
'members': idMembers
});
await channel.create();
channel.watch();
return channel;
}
}
Can anyone help me please?