Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/device_info_plus/device_info_plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Get current device information from within the Flutter application.

## Requirements

- Flutter >=3.22.0
- Dart >=3.4.0 <4.0.0
- Flutter >=3.29.0
- Dart >=3.7.0 <4.0.0
- iOS >=12.0
- MacOS >=10.14
- Android `compileSDK` 34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,30 @@ class DeviceInfoPlugin {
///
/// See: https://developer.android.com/reference/android/os/Build.html
Future<AndroidDeviceInfo> get androidInfo async =>
_cachedAndroidDeviceInfo ??=
AndroidDeviceInfo.fromMap((await _platform.deviceInfo()).data);
_cachedAndroidDeviceInfo ??= AndroidDeviceInfo.fromMap(
(await _platform.deviceInfo()).data,
);

/// This information does not change from call to call. Cache it.
IosDeviceInfo? _cachedIosDeviceInfo;

/// Information derived from `UIDevice`.
///
/// See: https://developer.apple.com/documentation/uikit/uidevice
Future<IosDeviceInfo> get iosInfo async => _cachedIosDeviceInfo ??=
IosDeviceInfo.fromMap((await _platform.deviceInfo()).data);
Future<IosDeviceInfo> get iosInfo async =>
_cachedIosDeviceInfo ??= IosDeviceInfo.fromMap(
(await _platform.deviceInfo()).data,
);

/// This information does not change from call to call. Cache it.
LinuxDeviceInfo? _cachedLinuxDeviceInfo;

/// Information derived from `/etc/os-release`.
///
/// See: https://www.freedesktop.org/software/systemd/man/os-release.html
Future<LinuxDeviceInfo> get linuxInfo async => _cachedLinuxDeviceInfo ??=
await _platform.deviceInfo() as LinuxDeviceInfo;
Future<LinuxDeviceInfo> get linuxInfo async =>
_cachedLinuxDeviceInfo ??=
await _platform.deviceInfo() as LinuxDeviceInfo;

/// This information does not change from call to call. Cache it.
WebBrowserInfo? _cachedWebBrowserInfo;
Expand All @@ -82,8 +86,10 @@ class DeviceInfoPlugin {
MacOsDeviceInfo? _cachedMacosDeviceInfo;

/// Returns device information for macos. Information sourced from Sysctl.
Future<MacOsDeviceInfo> get macOsInfo async => _cachedMacosDeviceInfo ??=
MacOsDeviceInfo.fromMap((await _platform.deviceInfo()).data);
Future<MacOsDeviceInfo> get macOsInfo async =>
_cachedMacosDeviceInfo ??= MacOsDeviceInfo.fromMap(
(await _platform.deviceInfo()).data,
);

WindowsDeviceInfo? _cachedWindowsDeviceInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DeviceInfoPlusLinuxPlugin extends DeviceInfoPlatform {

///
DeviceInfoPlusLinuxPlugin({@visibleForTesting FileSystem? fileSystem})
: _fileSystem = fileSystem ?? const LocalFileSystem();
: _fileSystem = fileSystem ?? const LocalFileSystem();

@override
Future<BaseDeviceInfo> deviceInfo() async {
Expand Down Expand Up @@ -50,8 +50,9 @@ class DeviceInfoPlusLinuxPlugin extends DeviceInfoPlatform {
}

Future<Map<String, String?>?> _getOsRelease() {
return _tryReadKeyValues('/etc/os-release').then((value) async =>
value ?? await _tryReadKeyValues('/usr/lib/os-release'));
return _tryReadKeyValues('/etc/os-release').then(
(value) async => value ?? await _tryReadKeyValues('/usr/lib/os-release'),
);
}

Future<Map<String, String?>?> _getLsbRelease() {
Expand Down Expand Up @@ -95,10 +96,12 @@ extension _Unquote on String {

extension _KeyValues on List<String> {
Map<String, String?> toKeyValues() {
return Map.fromEntries(map((line) {
final parts = line.split('=');
if (parts.length != 2) return MapEntry(line, null);
return MapEntry(parts.first, parts.last.unquote());
}));
return Map.fromEntries(
map((line) {
final parts = line.split('=');
if (parts.length != 2) return MapEntry(line, null);
return MapEntry(parts.first, parts.last.unquote());
}),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,30 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform {
/// Factory method that initializes the DeviceInfoPlus plugin platform
/// with an instance of the plugin for the web.
static void registerWith(Registrar registrar) {
DeviceInfoPlatform.instance =
DeviceInfoPlusWebPlugin(html.window.navigator);
DeviceInfoPlatform.instance = DeviceInfoPlusWebPlugin(
html.window.navigator,
);
}

@override
Future<BaseDeviceInfo> deviceInfo() {
return Future<WebBrowserInfo>.value(
WebBrowserInfo.fromMap(
{
'appCodeName': _navigator.appCodeName,
'appName': _navigator.appName,
'appVersion': _navigator.appVersion,
'deviceMemory': _navigator.safeDeviceMemory,
'language': _navigator.language,
'languages': _navigator.languages.toDart,
'platform': _navigator.platform,
'product': _navigator.product,
'productSub': _navigator.productSub,
'userAgent': _navigator.userAgent,
'vendor': _navigator.vendor,
'vendorSub': _navigator.vendorSub,
'hardwareConcurrency': _navigator.hardwareConcurrency,
'maxTouchPoints': _navigator.maxTouchPoints,
},
),
WebBrowserInfo.fromMap({
'appCodeName': _navigator.appCodeName,
'appName': _navigator.appName,
'appVersion': _navigator.appVersion,
'deviceMemory': _navigator.safeDeviceMemory,
'language': _navigator.language,
'languages': _navigator.languages.toDart,
'platform': _navigator.platform,
'product': _navigator.product,
'productSub': _navigator.productSub,
'userAgent': _navigator.userAgent,
'vendor': _navigator.vendor,
'vendorSub': _navigator.vendorSub,
'hardwareConcurrency': _navigator.hardwareConcurrency,
'maxTouchPoints': _navigator.maxTouchPoints,
}),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform {
// package:win32, so we have to manually define it here.
//
// ignore: non_constant_identifier_names
void Function(Pointer<OSVERSIONINFOEX>) RtlGetVersion =
DynamicLibrary.open('ntdll.dll').lookupFunction<
Void Function(Pointer<OSVERSIONINFOEX>),
void Function(Pointer<OSVERSIONINFOEX>)>('RtlGetVersion');
void Function(Pointer<OSVERSIONINFOEX>) RtlGetVersion = DynamicLibrary.open(
'ntdll.dll',
).lookupFunction<
Void Function(Pointer<OSVERSIONINFOEX>),
void Function(Pointer<OSVERSIONINFOEX>)
>('RtlGetVersion');

/// Returns a [WindowsDeviceInfo] with information about the device.
@override
Expand All @@ -44,30 +46,36 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform {
@visibleForTesting
WindowsDeviceInfo getInfo() {
final systemInfo = calloc<SYSTEM_INFO>();
final osVersionInfo = calloc<OSVERSIONINFOEX>()
..ref.dwOSVersionInfoSize = sizeOf<OSVERSIONINFOEX>();
final osVersionInfo =
calloc<OSVERSIONINFOEX>()
..ref.dwOSVersionInfoSize = sizeOf<OSVERSIONINFOEX>();

try {
final currentVersionKey = Registry.openPath(RegistryHive.localMachine,
path: r'SOFTWARE\Microsoft\Windows NT\CurrentVersion');
final currentVersionKey = Registry.openPath(
RegistryHive.localMachine,
path: r'SOFTWARE\Microsoft\Windows NT\CurrentVersion',
);
final buildLab = currentVersionKey.getStringValue('BuildLab') ?? '';
final buildLabEx = currentVersionKey.getStringValue('BuildLabEx') ?? '';
final digitalProductId =
currentVersionKey.getBinaryValue('DigitalProductId') ??
Uint8List.fromList([]);
Uint8List.fromList([]);
final displayVersion =
currentVersionKey.getStringValue('DisplayVersion') ?? '';
final editionId = currentVersionKey.getStringValue('EditionID') ?? '';
final installDate = DateTime.fromMillisecondsSinceEpoch(
1000 * (currentVersionKey.getIntValue('InstallDate') ?? 0));
1000 * (currentVersionKey.getIntValue('InstallDate') ?? 0),
);
final productId = currentVersionKey.getStringValue('ProductID') ?? '';
var productName = currentVersionKey.getStringValue('ProductName') ?? '';
final registeredOwner =
currentVersionKey.getStringValue('RegisteredOwner') ?? '';
final releaseId = currentVersionKey.getStringValue('ReleaseId') ?? '';

final sqmClientKey = Registry.openPath(RegistryHive.localMachine,
path: r'SOFTWARE\Microsoft\SQMClient');
final sqmClientKey = Registry.openPath(
RegistryHive.localMachine,
path: r'SOFTWARE\Microsoft\SQMClient',
);
final machineId = sqmClientKey.getStringValue('MachineId') ?? '';

GetSystemInfo(systemInfo);
Expand Down Expand Up @@ -140,8 +148,11 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform {
// Now allocate memory for a native string and call this a second time.
final lpBuffer = wsalloc(nSize.value);
try {
final result =
GetComputerNameEx(ComputerNameDnsFullyQualified, lpBuffer, nSize);
final result = GetComputerNameEx(
ComputerNameDnsFullyQualified,
lpBuffer,
nSize,
);

if (result != 0) {
return lpBuffer.toDartString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class AndroidDeviceInfo extends BaseDeviceInfo {
required this.isLowRamDevice,
required this.physicalRamSize,
required this.availableRamSize,
}) : supported32BitAbis = List<String>.unmodifiable(supported32BitAbis),
supported64BitAbis = List<String>.unmodifiable(supported64BitAbis),
supportedAbis = List<String>.unmodifiable(supportedAbis),
systemFeatures = List<String>.unmodifiable(systemFeatures),
super(data);
}) : supported32BitAbis = List<String>.unmodifiable(supported32BitAbis),
supported64BitAbis = List<String>.unmodifiable(supported64BitAbis),
supportedAbis = List<String>.unmodifiable(supportedAbis),
systemFeatures = List<String>.unmodifiable(systemFeatures),
super(data);

/// Android operating system version values derived from `android.os.Build.VERSION`.
final AndroidBuildVersion version;
Expand Down Expand Up @@ -175,7 +175,8 @@ class AndroidDeviceInfo extends BaseDeviceInfo {
return AndroidDeviceInfo._(
data: map,
version: AndroidBuildVersion._fromMap(
map['version']?.cast<String, dynamic>() ?? {}),
map['version']?.cast<String, dynamic>() ?? {},
),
board: map['board'],
bootloader: map['bootloader'],
brand: map['brand'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ class IosDeviceInfo extends BaseDeviceInfo {
physicalRamSize: map['physicalRamSize'],
availableRamSize: map['availableRamSize'],
isiOSAppOnMac: map['isiOSAppOnMac'],
utsname:
IosUtsname._fromMap(map['utsname']?.cast<String, dynamic>() ?? {}),
utsname: IosUtsname._fromMap(
map['utsname']?.cast<String, dynamic>() ?? {},
),
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/device_info_plus/device_info_plus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ dev_dependencies:
test: ^1.25.15

environment:
sdk: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"
sdk: ">=3.7.0 <4.0.0"
flutter: ">=3.29.0"
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ import 'package:flutter_test/flutter_test.dart';

void main() {
test('WebBrowserInfo from Map with values', () {
final info = WebBrowserInfo.fromMap(
{
'appCodeName': 'CODENAME',
'appName': 'NAME',
'appVersion': 'VERSION',
'deviceMemory': 64,
'language': 'en',
'languages': ['en', 'es'],
'platform': 'PLATFORM',
'product': 'PRODUCT',
'productSub': 'PRODUCTSUB',
'userAgent':
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0',
'vendor': 'VENDOR',
'vendorSub': 'VENDORSUB',
'hardwareConcurrency': 1,
'maxTouchPoints': 2,
},
);
final info = WebBrowserInfo.fromMap({
'appCodeName': 'CODENAME',
'appName': 'NAME',
'appVersion': 'VERSION',
'deviceMemory': 64,
'language': 'en',
'languages': ['en', 'es'],
'platform': 'PLATFORM',
'product': 'PRODUCT',
'productSub': 'PRODUCTSUB',
'userAgent':
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0',
'vendor': 'VENDOR',
'vendorSub': 'VENDORSUB',
'hardwareConcurrency': 1,
'maxTouchPoints': 2,
});

expect(info.appName, 'NAME');
expect(info.browserName, BrowserName.firefox);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ part '../model/android_device_info_fake.dart';
void main() {
group('$AndroidDeviceInfo fromMap | toMap', () {
test('fromMap should return $AndroidDeviceInfo with correct values', () {
final androidDeviceInfo =
AndroidDeviceInfo.fromMap(_fakeAndroidDeviceInfo);
final androidDeviceInfo = AndroidDeviceInfo.fromMap(
_fakeAndroidDeviceInfo,
);

expect(androidDeviceInfo.id, 'id');
expect(androidDeviceInfo.host, 'host');
Expand Down Expand Up @@ -47,8 +48,9 @@ void main() {
});

test('toMap should return map with correct key and map', () {
final androidDeviceInfo =
AndroidDeviceInfo.fromMap(_fakeAndroidDeviceInfo);
final androidDeviceInfo = AndroidDeviceInfo.fromMap(
_fakeAndroidDeviceInfo,
);

expect(androidDeviceInfo.data, _fakeAndroidDeviceInfo);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import 'package:device_info_plus_platform_interface/device_info_plus_platform_in
class MethodChannelDeviceInfo extends DeviceInfoPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
MethodChannel channel =
const MethodChannel('dev.fluttercommunity.plus/device_info');
MethodChannel channel = const MethodChannel(
'dev.fluttercommunity.plus/device_info',
);

// Generic method channel for all devices
@override
Future<BaseDeviceInfo> deviceInfo() async {
return BaseDeviceInfo(
(await channel.invokeMethod('getDeviceInfo')).cast<String, dynamic>());
(await channel.invokeMethod('getDeviceInfo')).cast<String, dynamic>(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
dependencies:
flutter:
sdk: flutter
meta: ^1.8.0
plugin_platform_interface: ^2.1.4
meta: ^1.16.0
plugin_platform_interface: ^2.1.8

dev_dependencies:
flutter_lints: ">=4.0.0 <6.0.0"
flutter_lints: ">=5.0.0 <7.0.0"
flutter_test:
sdk: flutter
mockito: ^5.4.0

environment:
sdk: ">=2.18.0 <4.0.0"
flutter: ">=3.3.0"
sdk: ">=3.7.0 <4.0.0"
flutter: ">=3.29.0"
Loading
Loading