sendInvitation static method

dynamic sendInvitation({
  1. required BuildContext context,
})

Implementation

static sendInvitation({required BuildContext context}) 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;
  }

  final prefs = await SharedPreferences.getInstance();
  if (prefs.getString(StringUtils.USER_DATA) == null) {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) =>
            InvitationForm(UserBean('', '', '', '', '', '', '')),
      ),
    );
  } else {
    Map jsons = json.decode(prefs.getString(StringUtils.USER_DATA)!);
    UserBean bean = UserBean(
        jsons['first_name'],
        jsons['last_name'],
        jsons['email'],
        jsons['phone'],
        jsons['country_id'],
        jsons['language'],
        jsons['deviceId']);
    showDialog<void>(
      context: context,
      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return AlertDialog(
          title: const Text(
              'Do you want to edit credentials or continue with saved data?'),
          actions: <Widget>[
            TextButton(
              child: const Text('Edit'),
              onPressed: () {
                Navigator.of(context).pop();
                Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => InvitationForm(bean)));
              },
            ),
            TextButton(
              child: const Text('Continue'),
              onPressed: () async {
                Navigator.of(context).pop();
                try {
                  final result = await InternetAddress.lookup('google.com');
                  if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
                    Route route = MaterialPageRoute(
                        builder: (context) =>
                            AppRegistrationScreen(bean, false));
                    Navigator.push(context, route);
                  }
                } on SocketException catch (_) {
                  CommonUtils.showToast(
                      StringUtils.CHECK_NETWORK, Colors.red);
                }
                //openNextScreen(context, bean);
              },
            ),
          ],
        );
      },
    );
  }
}