Home > Software engineering >  Throwing Exception While Relogging In
Throwing Exception While Relogging In

Time:02-16

Future<String> login() async {
    try {
      final authorizationTokenRequest = AuthorizationTokenRequest(
        auth0ClientID,
        auth0RedirectUrl,
        issuer: auth0Issuer,
        scopes: ['openid', 'profile', 'offline_access', 'email'],
        promptValues: ['login'],
      );

      final AuthorizationTokenResponse? result =
          await appAuth.authorizeAndExchangeCode(authorizationTokenRequest);

      debugPrint(result?.accessToken);

      return await _setLocalVariables(result);
    } on PlatformException {
      return 'User has Cancelled or no Internet';
    } catch (e) {
      return 'Unknown Error';
    }
  }

  // logout Function While Logging Out The RefreshToken also will be Deleted
  Future<bool> logout() async {
    await secureStorage.delete(key: refreshTokenKey);

    final url = Uri.https(
      auth0Domain,
      '/v2/logout',
      {
        'client_id': auth0ClientID,
        'federated': '',
        //'returnTo': 'YOUR_RETURN_LOGOUT_URL'
      },
    );

    final response = await http.get(
      url,
      headers: {'Authorization': 'Bearer $auth0AccessToken'},
    );

    debugPrint(
      'logout: ${response.request} ${response.statusCode} ${response.body}',
    );

    return response.statusCode == 200;
  }

ElevatedButton

ElevatedButton(
                              style: ElevatedButton.styleFrom(
                                primary: appPrimaryColor, // background
                                onPrimary: Colors.white, // foreground
                                fixedSize: Size(context.screenWidth * 0.80,
                                    context.screenHeight * 0.07),
                                onSurface: appPrimaryColor,
                                shape: RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(15),
                                ),
                              ),
                              onPressed: () {
                                loginAction(); // Calling the Login fucntion from the HomeScreen to Perform LoginAction
                              },

While the First Time Login in Its Logging in Properly After the Loggout and again login it throw error on

The following NoSuchMethodError was thrown while handling a gesture:

Class 'String' has no instance method 'call'. Receiver: "" Tried calling: call()

When the exception was thrown, this was the stack #0 Object.noSuchMethod #1 LoginScreen.build..

CodePudding user response:

NoSuchMethodError is usually thrown when you're trying to access a non-existent method from a class or Object. Common cause of this is possibly due to the class not yet being initialized or null.

  • Related