Skip to content

Commit

Permalink
fix(device_info_plus): device memory null error on Safari and Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaswanth-isani committed Dec 17, 2024
1 parent 95a12ee commit a6beb6c
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ 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
Expand All @@ -29,7 +28,7 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform {
'appCodeName': _navigator.appCodeName,
'appName': _navigator.appName,
'appVersion': _navigator.appVersion,
'deviceMemory': _navigator.deviceMemory,
'deviceMemory': _navigator.safeDeviceMemory(),
'language': _navigator.language,
'languages': _navigator.languages.toDart,
'platform': _navigator.platform,
Expand All @@ -45,3 +44,13 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform {
);
}
}

extension SafeNavigationGetterExtensions on html.Navigator {
double? safeDeviceMemory() {
try {
return deviceMemory;
} catch (e) {
return 0.0;
}
}
}

0 comments on commit a6beb6c

Please sign in to comment.