Skip to content

Commit 2b7cb08

Browse files
fix(device_info_plus): device memory null error on Safari and Firefox (#3401)
Co-authored-by: Miguel Beltran <[email protected]>
1 parent 8e70d3f commit 2b7cb08

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform {
2929
'appCodeName': _navigator.appCodeName,
3030
'appName': _navigator.appName,
3131
'appVersion': _navigator.appVersion,
32-
'deviceMemory': _navigator.deviceMemory,
32+
'deviceMemory': _navigator.safeDeviceMemory,
3333
'language': _navigator.language,
3434
'languages': _navigator.languages.toDart,
3535
'platform': _navigator.platform,
@@ -45,3 +45,16 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform {
4545
);
4646
}
4747
}
48+
49+
/// Some Navigator properties are not fully supported in all browsers.
50+
/// However, package:web does not provide a safe way to access these properties,
51+
/// and assumes they are always not null.
52+
///
53+
/// This extension provides a safe way to access these properties.
54+
///
55+
/// See: https://github.com/dart-lang/web/issues/326
56+
/// https://github.com/fluttercommunity/plus_plugins/issues/3391
57+
extension SafeNavigationGetterExtensions on html.Navigator {
58+
@JS('deviceMemory')
59+
external double? get safeDeviceMemory;
60+
}

0 commit comments

Comments
 (0)