collect static method

Future<GameDeviceInfo> collect(
  1. String sdkVersion
)

Collects the facts from the plugin (gameDeviceFacts). A missing plugin or any failure degrades each fact to its default. Never throws.

Implementation

static Future<GameDeviceInfo> collect(String sdkVersion) async {
  Map<Object?, Object?> raw = const {};
  try {
    raw =
        await _channel.invokeMapMethod<Object?, Object?>('gameDeviceFacts') ??
            const {};
  } catch (_) {
    _log.d('Game device facts unavailable, using defaults');
  }
  String str(String key) => raw[key] is String ? raw[key] as String : '';
  bool flag(String key, bool fallback) =>
      raw[key] is bool ? raw[key] as bool : fallback;
  int number(String key) => raw[key] is num ? (raw[key] as num).toInt() : 0;
  final reducedMotion = flag('reducedMotion', false);
  final lowPower = flag('lowPower', false);
  final thermal = str('thermal').isEmpty ? 'nominal' : str('thermal');
  final ramMb = number('ramMb');
  final cores = number('cores') > 0 ? number('cores') : _localCores();
  final sensors = raw['sensors'] is List
      ? (raw['sensors'] as List).whereType<String>().toList()
      : const <String>[];
  return GameDeviceInfo(
    osVersion: str('osVersion'),
    sdkVersion: sdkVersion,
    model: str('model'),
    locale: _locale(),
    timezone: str('timezone'),
    hapticsAllowed: flag('hapticsAllowed', false),
    soundAllowed: flag('soundAllowed', true),
    reducedMotion: reducedMotion,
    tier: computeGameTier(reducedMotion, lowPower, thermal, ramMb, cores),
    ramMb: ramMb,
    cores: cores,
    thermal: thermal,
    lowPower: lowPower,
    sensors: sensors,
  );
}