makeInterceptor static method

dynamic makeInterceptor(
  1. String className,
  2. String value, {
  3. String folderPath = networkingInterceptorsFolder,
  4. bool forceCreate = false,
  5. String? creationPath,
})

Create a new Interceptor.

Implementation

static makeInterceptor(String className, String value,
    {String folderPath = networkingInterceptorsFolder,
    bool forceCreate = false,
    String? creationPath}) async {
  String name = className.replaceAll(RegExp(r'(_?interceptor)'), "");

  // create missing directories in the project
  await _makeDirectory(folderPath);
  await createDirectoriesFromCreationPath(creationPath, folderPath);

  // create file path
  String filePath = createPathForDartFile(
      folderPath: folderPath,
      className: name,
      prefix: 'interceptor',
      creationPath: creationPath);

  await _checkIfFileExists(filePath, shouldForceCreate: forceCreate);
  await _createNewFile(filePath, value, onSuccess: () {
    MetroConsole.writeInGreen(
        '[Interceptor] ${name.snakeCase}_interceptor created 🎉');
  });
}