directory method

Directory directory(
  1. String dirPath
)

Returns a directory within the Directory

Directory androidDir = Directory('flutter-app/android');
Directory mainSrc = androidDir.directory("app/src/main");

Implementation

Directory directory(String dirPath) {
  final sb = StringBuffer(absolute.path);
  final path = sb.toString();
  if (!path.endsWith(Platform.pathSeparator) &&
      !dirPath.startsWith(Platform.pathSeparator)) {
    // no separator between dir and filePath
    sb.write(Platform.pathSeparator);
  }
  if (path.startsWith(Platform.pathSeparator) &&
      dirPath.startsWith(Platform.pathSeparator)) {
    // joining would cause a double //
    final path = dirPath.replaceFirst(Platform.pathSeparator, '');
    sb.write(path);
  } else {
    sb.write(dirPath);
  }
  return Directory(sb.toString());
}