registerDeviceData static method

Future<void> registerDeviceData()

Implementation

static Future<void> registerDeviceData() async {
  print('Registering device...');
  String deviceType;
  String devicePlatform;
  String deviceToken = await getDeviceToken();

  if (kIsWeb) {
    deviceType = 'Browser';
    devicePlatform = 'Web';
  } else if (Platform.isAndroid) {
    deviceType = 'Smartphone';
    devicePlatform = 'Android';
  } else if (Platform.isIOS) {
    deviceType = 'Smartphone';
    devicePlatform = 'iOS';
  } else if (Platform.isWindows) {
    deviceType = 'Desktop';
    devicePlatform = 'Windows';
  } else if (Platform.isMacOS) {
    deviceType = 'Desktop';
    devicePlatform = 'macOS';
  } else if (Platform.isLinux) {
    deviceType = 'Desktop';
    devicePlatform = 'Linux';
  } else {
    deviceType = 'Unknown';
    devicePlatform = 'Unknown';
  }

  Map<String, dynamic> data = {
    'deviceType': deviceType,
    'deviceToken': deviceToken,
    'devicePlatform': devicePlatform,
  };
  try {
    await registerDevice(data);
  } catch (e) {
    print('Error during device registration: $e');
  }
}