openChatRoomByUsername method

Future openChatRoomByUsername(
  1. BuildContext context,
  2. String username
)

Implementation

Future openChatRoomByUsername(
  BuildContext context,
  String username,
) async {
  username = "$username@chat.io";
  final user = await getUserByUsername(username);
  if (user == null) {
    // ignore: use_build_context_synchronously
    return await showDialog(
      context: context,
      builder: (context) => AlertDialog(
        actions: [
          TextButton(
            onPressed: () {
              Navigator.of(context).pop();
            },
            child: const Text('OK'),
          ),
        ],
        content: const Text(
          "Couldn't find user account",
        ),
        title: const Text('Error'),
      ),
    );
  }
  final room = await FirebaseChatCore.instance.createRoom(user);
  return await openChatRoom(context, room);
}