getDeviceDescription static method

Future<String> getDeviceDescription()

A human readable "brand model product" for the x-device header.

Reads the info object for whichever platform is actually running - getAndroidDeviceInfo throws on iOS, and it used to be called on the way out of every request regardless of platform.

Implementation

static Future<String> getDeviceDescription() async {
  if (_cachedDeviceDescription != null) return _cachedDeviceDescription!;

  var description = '';
  try {
    if (Platform.isAndroid) {
      var info = await _deviceInfoPlugin.androidInfo;
      description = "${info.brand} ${info.model} ${info.product}";
    } else if (Platform.isIOS) {
      var info = await _deviceInfoPlugin.iosInfo;
      description = "Apple ${info.model} ${info.utsname.machine}";
    }
  } catch (err, stackTrace) {
    // The header is diagnostic only - never fail a request over it.
    ErrorReporter.log(err, stackTrace);
  }

  _cachedDeviceDescription = description;
  return description;
}