DeviceCapabilities.fromJson constructor

DeviceCapabilities.fromJson(
  1. Map<Object?, Object?>? json
)

Reads the keys physicalMemoryMB, availableMemoryMB and freeDiskMB; a missing, negative or non-numeric value is unknown.

Implementation

factory DeviceCapabilities.fromJson(Map<Object?, Object?>? json) {
  int? mb(String key) => switch (json?[key]) {
    final num n when n >= 0 => n.toInt(),
    _ => null,
  };
  return DeviceCapabilities(
    physicalMemoryMB: mb('physicalMemoryMB'),
    availableMemoryMB: mb('availableMemoryMB'),
    freeDiskMB: mb('freeDiskMB'),
  );
}