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
…#3401)

Co-authored-by: Miguel Beltran <m@beltran.work>
  • Loading branch information
bhaswanth-isani and miquelbeltran authored Dec 18, 2024
1 parent 8e70d3f commit 2b7cb08
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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 +45,16 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform {
);
}
}

/// Some Navigator properties are not fully supported in all browsers.
/// However, package:web does not provide a safe way to access these properties,
/// and assumes they are always not null.
///
/// This extension provides a safe way to access these properties.
///
/// See: https://github.com/dart-lang/web/issues/326
/// https://github.com/fluttercommunity/plus_plugins/issues/3391
extension SafeNavigationGetterExtensions on html.Navigator {
@JS('deviceMemory')
external double? get safeDeviceMemory;
}

0 comments on commit 2b7cb08

Please sign in to comment.