I'm using the global context as outlined in Get the Global Context in Flutter in a RetryPolicy which references an auth service when I get a 401:
class ExpiredTokenRetryPolicy extends RetryPolicy {
@override
int get maxRetryAttempts => 1;
@override
bool shouldAttemptRetryOnException(Exception reason) {
return false;
}
@override
Future<bool> shouldAttemptRetryOnResponse(ResponseData response) async {
if (response.statusCode == 401) {
await Provider.of<UserProfileService>(NavigationService.navigatorKey.currentContext!, listen: false).initLogin();
return true;
}
return false;
}
}
Randomly the NavigationService.navigatorKey.currentContext
is null, is there anyway I can reinitialise this?