Files
rog_app/lib/services/device_info_service.dart

40 lines
1.3 KiB
Dart

import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:device_info_plus/device_info_plus.dart';
class DeviceInfoService {
static Future<Map<String, dynamic>> getDeviceInfo() async {
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
if (Platform.isAndroid) {
final AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
return {
'os': 'Android',
'os_version': androidInfo.version.release,
'device_model': androidInfo.model,
'app_version': packageInfo.version,
'app_build_number': packageInfo.buildNumber,
};
} else if (Platform.isIOS) {
final IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
return {
'os': 'iOS',
'os_version': iosInfo.systemVersion,
'device_model': iosInfo.model,
'app_version': packageInfo.version,
'app_build_number': packageInfo.buildNumber,
};
} else {
return {
'os': Platform.operatingSystem,
'os_version': Platform.operatingSystemVersion,
'app_version': packageInfo.version,
'app_build_number': packageInfo.buildNumber,
};
}
}
}