addAtSign method

Future addAtSign(
  1. dynamic context, {
  2. String? atSign,
  3. String? nickName,
})

Implementation

Future<dynamic> addAtSign(
  context, {
  String? atSign,
  String? nickName,
}) async {
  if (atSign == null || atSign == '') {
    getAtSignError = TextStrings().emptyAtsign;

    return true;
  } else if (atSign[0] != '@') {
    atSign = '@' + atSign;
  }
  atSign = atSign.toLowerCase().trim();

  if (atSign == atClientInstance?.currentAtSign) {
    getAtSignError = TextStrings().addingLoggedInUser;

    return true;
  }
  try {
    isContactPresent = false;

    getAtSignError = '';
    var contact = AtContact();

    checkAtSign = await checkAtsign(atSign);

    if (!checkAtSign!) {
      getAtSignError = TextStrings().unknownAtsign(atSign);
    } else {
      contactList.forEach((element) async {
        if (element!.atSign == atSign) {
          getAtSignError = TextStrings().atsignExists(atSign);
          isContactPresent = true;
          return;
        }
      });
    }
    if (!isContactPresent && checkAtSign!) {
      var details = await getContactDetails(atSign, nickName);
      contact = AtContact(
        atSign: atSign,
        tags: details,
      );
      print('details==>${contact.atSign}');
      var result = await atContactImpl.add(contact).catchError((e) {
        print('error to add contact => $e');
      });
      print(result);
      fetchContacts();
    }
  } catch (e) {
    print(e);
  }
}