onRequest method

  1. @override
Future<void> onRequest(
  1. RequestOptions options,
  2. RequestInterceptorHandler handler
)

Called when the request is about to be sent.

Implementation

@override
Future<void> onRequest(options, handler) async {
  await Future.delayed(const Duration(milliseconds: 350));

  for (final key in dataMap.keys) {
    if (options.path.contains(key)) {
      return handler.resolve(
        Response(
          requestOptions: options,
          data: dataMap[key],
        ),
      );
    }
  }

  return handler.next(options);
}