|
| 1 | +import 'package:device_info_plus/device_info_plus.dart'; |
| 2 | + |
| 3 | +import 'platform.dart'; |
| 4 | + |
| 5 | +/// Returns device information as a Map. |
| 6 | +Future<Map<String, dynamic>> getDeviceInfo() async { |
| 7 | + BaseDeviceInfo deviceInfo = await DeviceInfoPlugin().deviceInfo; |
| 8 | + return deviceInfo.asMap(); |
| 9 | +} |
| 10 | + |
| 11 | +extension DeviceInfoExtension on BaseDeviceInfo { |
| 12 | + Map<String, dynamic> asMap() { |
| 13 | + var deviceInfo = this; |
| 14 | + |
| 15 | + if (isWebPlatform()) { |
| 16 | + deviceInfo = (deviceInfo as WebBrowserInfo); |
| 17 | + return { |
| 18 | + "browser_name": deviceInfo.browserName.name, |
| 19 | + "app_code_name": deviceInfo.appCodeName, |
| 20 | + "app_name": deviceInfo.appName, |
| 21 | + "app_version": deviceInfo.appVersion, |
| 22 | + "device_memory": deviceInfo.deviceMemory, |
| 23 | + "language": deviceInfo.language, |
| 24 | + "languages": deviceInfo.languages, |
| 25 | + "platform": deviceInfo.platform, |
| 26 | + "product": deviceInfo.product, |
| 27 | + "product_sub": deviceInfo.productSub, |
| 28 | + "user_agent": deviceInfo.userAgent, |
| 29 | + "vendor": deviceInfo.vendor, |
| 30 | + "vendor_sub": deviceInfo.vendorSub, |
| 31 | + "max_touch_points": deviceInfo.maxTouchPoints, |
| 32 | + "hardware_concurrency": deviceInfo.hardwareConcurrency, |
| 33 | + }; |
| 34 | + } else { |
| 35 | + if (isAndroidMobile()) { |
| 36 | + deviceInfo = (deviceInfo as AndroidDeviceInfo); |
| 37 | + return { |
| 38 | + "available_ram_size": deviceInfo.availableRamSize, |
| 39 | + "board": deviceInfo.board, |
| 40 | + "bootloader": deviceInfo.bootloader, |
| 41 | + "brand": deviceInfo.brand, |
| 42 | + "device": deviceInfo.device, |
| 43 | + "display": deviceInfo.display, |
| 44 | + "fingerprint": deviceInfo.fingerprint, |
| 45 | + "free_disk_size": deviceInfo.freeDiskSize, |
| 46 | + "hardware": deviceInfo.hardware, |
| 47 | + "host": deviceInfo.host, |
| 48 | + "id": deviceInfo.id, |
| 49 | + "is_low_ram_device": deviceInfo.isLowRamDevice, |
| 50 | + "is_physical_device": deviceInfo.isPhysicalDevice, |
| 51 | + "manufacturer": deviceInfo.manufacturer, |
| 52 | + "model": deviceInfo.model, |
| 53 | + "name": deviceInfo.name, |
| 54 | + "physical_ram_size": deviceInfo.physicalRamSize, |
| 55 | + "product": deviceInfo.product, |
| 56 | + "supported_32_bit_abis": deviceInfo.supported32BitAbis, |
| 57 | + "supported_64_bit_abis": deviceInfo.supported64BitAbis, |
| 58 | + "supported_abis": deviceInfo.supportedAbis, |
| 59 | + "system_features": deviceInfo.systemFeatures, |
| 60 | + "tags": deviceInfo.tags, |
| 61 | + "total_disk_size": deviceInfo.totalDiskSize, |
| 62 | + "type": deviceInfo.type, |
| 63 | + "version": { |
| 64 | + 'base_os': deviceInfo.version.baseOS, |
| 65 | + 'sdk': deviceInfo.version.sdkInt, |
| 66 | + 'release': deviceInfo.version.release, |
| 67 | + 'code_name': deviceInfo.version.codename, |
| 68 | + 'incremental': deviceInfo.version.incremental, |
| 69 | + 'preview_sdk': deviceInfo.version.previewSdkInt, |
| 70 | + 'security_patch': deviceInfo.version.securityPatch, |
| 71 | + }, |
| 72 | + }; |
| 73 | + } else if (isIOSMobile()) { |
| 74 | + deviceInfo = (deviceInfo as IosDeviceInfo); |
| 75 | + return { |
| 76 | + "available_ram_size": deviceInfo.availableRamSize, |
| 77 | + "free_disk_size": deviceInfo.freeDiskSize, |
| 78 | + "is_ios_app_on_mac": deviceInfo.isiOSAppOnMac, |
| 79 | + "is_physical_device": deviceInfo.isPhysicalDevice, |
| 80 | + "localized_model": deviceInfo.localizedModel, |
| 81 | + "model": deviceInfo.model, |
| 82 | + "model_name": deviceInfo.modelName, |
| 83 | + "name": deviceInfo.name, |
| 84 | + "physical_ram_size": deviceInfo.physicalRamSize, |
| 85 | + "system_name": deviceInfo.systemName, |
| 86 | + "system_version": deviceInfo.systemVersion, |
| 87 | + "total_disk_size": deviceInfo.totalDiskSize, |
| 88 | + "utsname": { |
| 89 | + "machine": deviceInfo.utsname.machine, |
| 90 | + "node_name": deviceInfo.utsname.nodename, |
| 91 | + "release": deviceInfo.utsname.release, |
| 92 | + "sys_name": deviceInfo.utsname.sysname, |
| 93 | + "version": deviceInfo.utsname.version, |
| 94 | + }, |
| 95 | + "identifier_for_vendor": deviceInfo.identifierForVendor, |
| 96 | + }; |
| 97 | + } else if (isLinuxDesktop()) { |
| 98 | + deviceInfo = (deviceInfo as LinuxDeviceInfo); |
| 99 | + return { |
| 100 | + "name": deviceInfo.name, |
| 101 | + "id": deviceInfo.id, |
| 102 | + "pretty_name": deviceInfo.prettyName, |
| 103 | + "version": deviceInfo.version, |
| 104 | + "id_like": deviceInfo.idLike, |
| 105 | + "version_code_name": deviceInfo.versionCodename, |
| 106 | + "version_id": deviceInfo.versionId, |
| 107 | + "build_id": deviceInfo.buildId, |
| 108 | + "variant": deviceInfo.variant, |
| 109 | + "variant_id": deviceInfo.variantId, |
| 110 | + "machine_id": deviceInfo.machineId, |
| 111 | + }; |
| 112 | + } else if (isMacOSDesktop()) { |
| 113 | + deviceInfo = (deviceInfo as MacOsDeviceInfo); |
| 114 | + return { |
| 115 | + "active_cpus": deviceInfo.activeCPUs, |
| 116 | + "arch": deviceInfo.arch, |
| 117 | + "computer_name": deviceInfo.computerName, |
| 118 | + "cpu_frequency": deviceInfo.cpuFrequency, |
| 119 | + "host_name": deviceInfo.hostName, |
| 120 | + "kernel_version": deviceInfo.kernelVersion, |
| 121 | + "major_version": deviceInfo.majorVersion, |
| 122 | + "memory_size": deviceInfo.memorySize, |
| 123 | + "minor_version": deviceInfo.minorVersion, |
| 124 | + "model": deviceInfo.model, |
| 125 | + "model_name": deviceInfo.modelName, |
| 126 | + "os_release": deviceInfo.osRelease, |
| 127 | + "patch_version": deviceInfo.patchVersion, |
| 128 | + "system_guid": deviceInfo.systemGUID, |
| 129 | + }; |
| 130 | + } else if (isWindowsDesktop()) { |
| 131 | + deviceInfo = (deviceInfo as WindowsDeviceInfo); |
| 132 | + return { |
| 133 | + "computer_name": deviceInfo.computerName, |
| 134 | + "number_of_cores": deviceInfo.numberOfCores, |
| 135 | + "system_memory": deviceInfo.systemMemoryInMegabytes, |
| 136 | + "user_name": deviceInfo.userName, |
| 137 | + "major_version": deviceInfo.majorVersion, |
| 138 | + "minor_version": deviceInfo.minorVersion, |
| 139 | + "build_number": deviceInfo.buildNumber, |
| 140 | + "platform_id": deviceInfo.platformId, |
| 141 | + "csd_version": deviceInfo.csdVersion, |
| 142 | + "service_pack_major": deviceInfo.servicePackMajor, |
| 143 | + "service_pack_minor": deviceInfo.servicePackMinor, |
| 144 | + "suit_mask": deviceInfo.suitMask, |
| 145 | + "product_type": deviceInfo.productType, |
| 146 | + "reserved": deviceInfo.reserved, |
| 147 | + "build_lab": deviceInfo.buildLab, |
| 148 | + "build_lab_ex": deviceInfo.buildLabEx, |
| 149 | + // "digital_product_id": deviceInfo.digitalProductId, |
| 150 | + "display_version": deviceInfo.displayVersion, |
| 151 | + "edition_id": deviceInfo.editionId, |
| 152 | + "install_date": deviceInfo.installDate, |
| 153 | + "product_id": deviceInfo.productId, |
| 154 | + "product_name": deviceInfo.productName, |
| 155 | + "registered_owner": deviceInfo.registeredOwner, |
| 156 | + "release_id": deviceInfo.releaseId, |
| 157 | + "device_id": deviceInfo.deviceId, |
| 158 | + }; |
| 159 | + } |
| 160 | + return {}; |
| 161 | + } |
| 162 | + } |
| 163 | +} |
0 commit comments