getStorageHealth method

  1. @override
Future<Map<String, dynamic>> getStorageHealth()
override

Raw storage metrics map from the host.

Implementation

@override
Future<Map<String, dynamic>> getStorageHealth() async {
  try {
    final estimate = await web.window.navigator.storage.estimate().toDart;
    final quota = estimate.quota.toInt();
    final usage = estimate.usage.toInt();
    final free = (quota - usage).clamp(0, quota);
    final percent = quota > 0 ? (usage / quota) * 100 : 0.0;
    return <String, dynamic>{
      'total_bytes': quota,
      'free_bytes': free,
      'used_bytes': usage,
      'usage_percent': percent,
      'is_low_storage': false,
    };
  } catch (_) {
    return <String, dynamic>{
      'total_bytes': 0,
      'free_bytes': 0,
      'used_bytes': 0,
      'usage_percent': 0.0,
      'is_low_storage': false,
    };
  }
}