mkDevice static method

Future<Device> mkDevice()

Implementation

static Future<Device> mkDevice() async {

  DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  PackageInfo packageInfo = await PackageInfo.fromPlatform();
  Device device = Device();
  device.lastAppVersionName = packageInfo.version;
  device.lastAppVersionCode = packageInfo.buildNumber;

  // Check if web app
  if (kIsWeb) {
    WebBrowserInfo info = await deviceInfo.webBrowserInfo;
    device.deviceType = "Web";
    device.displayName = info.product;
    //device.remoteId = info.platform;
    device.osName = info.browserName.toString();
    device.make = info.vendor;
    device.model = info.vendorSub;
    device.osVersion = info.userAgent;

  } else if (defaultTargetPlatform == TargetPlatform.android ) {
    AndroidDeviceInfo info = await deviceInfo.androidInfo;
    device.deviceType = "Android";
    device.displayName = info.fingerprint;
    device.remoteId = info.androidId;
    device.osName = "Android - ${info.version.baseOS} ${info.version.codename}";
    device.osVersion = "${info.version.codename} ${info.version.sdkInt} ${info.version.securityPatch}";
    device.make = info.manufacturer;
    device.model = info.model;

  } else if (defaultTargetPlatform == TargetPlatform.iOS ) {
    IosDeviceInfo info = await deviceInfo.iosInfo;
    device.deviceType = "iOS";
    device.displayName = info.name;
    device.remoteId = info.identifierForVendor;
    device.osName = info.localizedModel;
    device.osVersion = info.systemVersion;
    device.make = info.systemName;
    device.model = info.model;

  } else if (defaultTargetPlatform == TargetPlatform.windows) {
    WindowsDeviceInfo info = await deviceInfo.windowsInfo;
    device.deviceType = "Windows";
    device.displayName = info.computerName;
    device.osName = "Windows";

  } else if (defaultTargetPlatform == TargetPlatform.linux) {
    LinuxDeviceInfo info = await deviceInfo.linuxInfo;
    device.deviceType = "Linux";
    device.displayName = info.name;
    device.remoteId = info.machineId;
    device.osName = info.prettyName;
    device.osVersion = info.version;
    device.make = info.variant;
    device.model = info.buildId;

  } else if (defaultTargetPlatform == TargetPlatform.macOS) {
    MacOsDeviceInfo info = await deviceInfo.macOsInfo;
    device.deviceType = "MacOS";
    device.displayName = info.computerName;
    device.osName = info.osRelease;
    device.osVersion = info.kernelVersion;
    device.make = info.hostName;
    device.model = info.model;
  } else if (defaultTargetPlatform == TargetPlatform.fuchsia) {
    device.deviceType = "Fuchsia";
    device.displayName = deviceInfo.toString();
  } else {
    device.deviceType = "Unknown";
    device.displayName = "Unknown";
  }
  return device;

}