sendInvitationInBackground static method
dynamic
sendInvitationInBackground({})
Implementation
static sendInvitationInBackground({
required BuildContext context,
required String firstName,
required String lastName,
required String email,
required String countryCode,
required String language,
required String number,
}) async {
// Navigator.of(context).pop();
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
CommonUtils.showToast("Please wait...", Colors.white);
CommonUtils.GetCountryListData(context).then((value) async {
if (StringUtils.APP_ID.isEmpty ||
StringUtils.APP_SECRET.isEmpty ||
StringUtils.APP_EMAIL.isEmpty ||
StringUtils.YOUR_APP_NAME.isEmpty) {
CommonUtils.showToast(
"Please initialize app with appId, secreteKey Your registered email address and App Name",
Colors.black);
return;
}
if (firstName.length <= 0) {
CommonUtils.showToast(StringUtils.ERROR_FIRST_NAME, Colors.red);
} else if (lastName.length <= 0) {
CommonUtils.showToast(StringUtils.ERROR_LAST_NAME, Colors.red);
} else if (email.length <= 0) {
CommonUtils.showToast(StringUtils.ERROR_EMAIL, Colors.red);
} else if (!CommonUtils.validateEmail(email)) {
CommonUtils.showToast(StringUtils.ERROR_VALID_EMAIL, Colors.red);
} else if (number.length < 5) {
CommonUtils.showToast(StringUtils.ERROR_NUMBER, Colors.red);
} else if (ListUtil.countryList
.where((element) => (element.cncode!.compareTo(countryCode)) == 0)
.isEmpty) {
CommonUtils.showToast(StringUtils.ERROR_COUNTRY, Colors.red);
} else if (language == '') {
CommonUtils.showToast('Select Language', Colors.red);
} else if (!ListUtil.language_list.contains(language)) {
CommonUtils.showToast(StringUtils.ERROR_LANGUAGE, Colors.red);
} else {
if (!number.contains("+")) {
number = ListUtil.countryList
.firstWhere((element) =>
element.cncode.toString().compareTo(countryCode) == 0)
.callCode
.toString() +
number;
}
final deviceInfoPlugin = DeviceInfoPlugin();
final deviceInfo = await deviceInfoPlugin.deviceInfo;
String deviceId = deviceInfo.data["id"] ?? "";
UserBean bean = UserBean(
firstName,
lastName,
email,
number,
// ListUtil.country_sort_code_list.indexOf(countryCode).toString(),
countryCode,
language,
deviceId,
);
final prefs = await SharedPreferences.getInstance();
prefs.setString(StringUtils.USER_DATA, jsonEncode(bean.toJson()));
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => AppRegistrationScreen(bean, true),
// builder: (context) => const Text('Data'),
),
);
}
} on SocketException catch (_) {
CommonUtils.showToast(StringUtils.CHECK_NETWORK, Colors.red);
}
}
});
}
} on SocketException catch (_) {
CommonUtils.showToast(StringUtils.CHECK_NETWORK, Colors.red);
}
}