Skip to content

Commit a6beb6c

Browse files
fix(device_info_plus): device memory null error on Safari and Firefox
1 parent 95a12ee commit a6beb6c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform {
1717
/// Factory method that initializes the DeviceInfoPlus plugin platform
1818
/// with an instance of the plugin for the web.
1919
static void registerWith(Registrar registrar) {
20-
DeviceInfoPlatform.instance =
21-
DeviceInfoPlusWebPlugin(html.window.navigator);
20+
DeviceInfoPlatform.instance = DeviceInfoPlusWebPlugin(html.window.navigator);
2221
}
2322

2423
@override
@@ -29,7 +28,7 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform {
2928
'appCodeName': _navigator.appCodeName,
3029
'appName': _navigator.appName,
3130
'appVersion': _navigator.appVersion,
32-
'deviceMemory': _navigator.deviceMemory,
31+
'deviceMemory': _navigator.safeDeviceMemory(),
3332
'language': _navigator.language,
3433
'languages': _navigator.languages.toDart,
3534
'platform': _navigator.platform,
@@ -45,3 +44,13 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform {
4544
);
4645
}
4746
}
47+
48+
extension SafeNavigationGetterExtensions on html.Navigator {
49+
double? safeDeviceMemory() {
50+
try {
51+
return deviceMemory;
52+
} catch (e) {
53+
return 0.0;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)