Sunday, October 22, 2023
HomeiOS Developmentios - Why is my flutter app utilizing a lot storage in...

ios – Why is my flutter app utilizing a lot storage in ‘Paperwork & Information’?


I’m at present perplexed as to why my app is utilizing a lot storage, as displayed in iPhone Storage settings.

Screenshot of my app's storage in iPhone settings

I ran the next methodology to get an approximation of how a lot storage im utilizing in my app:

Future<void> listFilesInAllDirectories() async {
  closing Listing tempDir = await getTemporaryDirectory();
  closing Listing appDocDir = await getApplicationDocumentsDirectory();
  closing Listing appSupportDir = await getApplicationSupportDirectory();
  closing Listing libraryDir = await getLibraryDirectory();

  Record<Listing> directories = [tempDir, appDocDir, appSupportDir, libraryDir];

  int grandTotalSize = 0;

  for (var listing in directories) {
    int totalSize = await getDirectorySize(listing);

    if (totalSize > 0) { // Skip over directories that don't include any recordsdata
      grandTotalSize += totalSize;
      print("Listing: ${listing.path}");
      double sizeInMB = totalSize / (1024 * 1024);
      print("Complete measurement of listing: ${sizeInMB.toStringAsFixed(2)} MB");
    }
  }

  double grandTotalSizeInMB = grandTotalSize / (1024 * 1024);
  print("Grand complete measurement: ${grandTotalSizeInMB.toStringAsFixed(2)} MB");
}

Future<int> getDirectorySize(Listing dir) async {
  int measurement = 0;
  strive {
    Record<FileSystemEntity> kids = dir.listSync();
    for (var baby in kids) {
      if (baby is File) {
        measurement += await baby.size();
      } else if (baby is Listing) {
        measurement += await getDirectorySize(baby);
      }
    }
  } catch (e) {
    print("An error occurred: $e");
  }
  return measurement;
}

And this methodology outputted the next:

flutter: Listing: /var/cellular/Containers/Information/Utility/4258E4C7-1B2C-428F-BCB5-782683E12F51/Library/Caches
flutter: Complete measurement of listing: 7.18 MB
flutter: Listing: /var/cellular/Containers/Information/Utility/4258E4C7-1B2C-428F-BCB5-782683E12F51/Paperwork
flutter: Complete measurement of listing: 146.43 MB
flutter: Listing: /var/cellular/Containers/Information/Utility/4258E4C7-1B2C-428F-BCB5-782683E12F51/Library/Utility Assist
flutter: Complete measurement of listing: 0.11 MB
flutter: Listing: /var/cellular/Containers/Information/Utility/4258E4C7-1B2C-428F-BCB5-782683E12F51/Library
flutter: Complete measurement of listing: 12.49 MB
flutter: Grand complete measurement: 166.21 MB

For Context, in my app I at present am solely storing pictures completely within the Utility Paperwork Listing. I do use the Short-term Listing nonetheless I delete all recordsdata I create on this folder after they’ve been used for his or her function. And earlier than I ran this ‘experiment’, I cleaned this folder with one other dart script.

I might actually recognize if somebody has any suspicions of what’s going on right here and will present an evidence as to how my app is utilizing a lot storage in Paperwork & Information?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments