Skip to content

Commit

Permalink
improved extension
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelbeltran committed Dec 17, 2024
1 parent 926c805 commit 06c0ad7
Showing 1 changed file with 11 additions and 9 deletions.
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.safeDeviceMemory(),
'deviceMemory': _navigator.safeDeviceMemory,
'language': _navigator.language,
'languages': _navigator.languages.toDart,
'platform': _navigator.platform,
Expand All @@ -46,13 +46,15 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform {
}
}

// TODO: Remove when https://github.com/dart-lang/web/issues/326 is resolved
/// 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 {
double? safeDeviceMemory() {
try {
return deviceMemory;
} catch (e) {
return null;
}
}
@JS('deviceMemory')
external double? get safeDeviceMemory;
}

0 comments on commit 06c0ad7

Please sign in to comment.