getStorageSize static method

Future<double> getStorageSize(
  1. FileSystemEntity file
)

获取存储大小

Implementation

static Future<double> getStorageSize(FileSystemEntity file) async {
  try {
    if (file is File) {
      int length = await file.length();
      return length.toDouble();
    }
    if (file is Directory) {
      final List<FileSystemEntity> children = file.listSync();
      double total = 0;
      for (final FileSystemEntity child in children) {
        total += await getStorageSize(child);
      }
      return total;
    }
    return 0;
  } catch (e) {
    return 0;
  }
}