registerDeviceData method

Future<void> registerDeviceData()

Implementation

Future<void> registerDeviceData() async {
  final ConfigurationService _configurationService = ConfigurationService();
  final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  print('Registering device...');
  print(deviceInfo);
  String deviceName;
  String deviceType;
  String devicePlatform;

  if (kIsWeb) {
    WebBrowserInfo webInfo = await deviceInfo.webBrowserInfo;
    deviceName = webInfo.userAgent ?? 'Unknown Web Device';
    deviceType = 'Browser';
    devicePlatform = 'Web';
  } else if (Platform.isAndroid) {
    AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
    deviceName = androidInfo.model;
    deviceType = 'Smartphone';
    devicePlatform = 'Android';
  } else if (Platform.isIOS) {
    IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
    deviceName = iosInfo.utsname.machine;
    deviceType = 'Smartphone';
    devicePlatform = 'iOS';
  } else if (Platform.isWindows) {
    WindowsDeviceInfo windowsInfo = await deviceInfo.windowsInfo;
    deviceName = windowsInfo.computerName;
    deviceType = 'Desktop';
    devicePlatform = 'Windows';
  } else if (Platform.isMacOS) {
    MacOsDeviceInfo macInfo = await deviceInfo.macOsInfo;
    deviceName = macInfo.model;
    deviceType = 'Desktop';
    devicePlatform = 'macOS';
  } else if (Platform.isLinux) {
    LinuxDeviceInfo linuxInfo = await deviceInfo.linuxInfo;
    deviceName = linuxInfo.name;
    deviceType = 'Desktop';
    devicePlatform = 'Linux';
  } else {
    deviceName = 'Unknown Device';
    deviceType = 'Unknown';
    devicePlatform = 'Unknown';
  }

  Map<String, dynamic> data = {
    'appdomain': 'auth.3u.gg',
    'deviceName': deviceName,
    'deviceType': deviceType,
    'deviceToken': 'abc123token',
    'devicePlatform': devicePlatform,
  };
  await _configurationService.registerDevice(data);
}