Guys how to do i cancel the api request using aws amplify api as rest operation is the object that has .cancel() property but in our architecture we have a repository layer that has the rest api endpoints defined within the function and the rest option object is not available from outside, as we only want the api url and body as the parameters to passed into the methods of the api class. Below is a sample of the mentioned code: Future<Map<String, dynamic>> get( String path, { String? body, Duration? customTimeoutDuration, Map<String, String>? queryParameters, Map<String, String>? headers, }) async { try { RestOptions getOptions = RestOptions( path: path, body: body.isNull() ? null : Uint8List.fromList(body!.codeUnits), headers: headers, queryParameters: queryParameters, ); RestOperation getOperation = Amplify.API.get(restOptions: getOptions); RestResponse getResponse = await getOperation.response .timeout(customTimeoutDuration ?? _defaultTimeoutDuration); if (getResponse.statusCode >= 200 && getResponse.statusCode < 300) { return jsonDecode(String.fromCharCodes(getResponse.data)); } } on ApiException catch (e) { //Do something on error }
To access cancel method we need to take out the RestOptions class, which we dont want to, is there any other option like Dio that passes the cancelToken inside the function param