Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(device_info_plus)!: Remove Display Metrics from Android Device Info #2731

Merged
merged 5 commits into from
Mar 19, 2024

Conversation

miquelbeltran
Copy link
Member

@miquelbeltran miquelbeltran commented Mar 19, 2024

Description

Following the discussion in #2688 (comment)

  • Display Metrics on Android depend on the Activity context and should not be obtained from the Application context.
  • This means that Flutter applications that use this plugin would require that they are attached to an Activity.
  • Plugin users can use better methods to obtain display information, e.g. MediaQuery DisplayFeature: https://api.flutter.dev/flutter/dart-ui/DisplayFeature-class.html that also support multiple displays, foldables, etc.
  • To keep this plugin independent of the Android Activity lifecycle, I remove the Display Metrics part from the Android device info, instead users should use MediaQuery.

Related Issues

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

@miquelbeltran
Copy link
Member Author

@ChristianEdwardPadilla fyi, please comment on this.

@miquelbeltran miquelbeltran requested a review from vbuberen March 19, 2024 06:56
@miquelbeltran miquelbeltran changed the title fix(device_info_plus)!: Remove Display Metrics from Android Device Info fix(device_info_plus)!: Remove Display Metrics from Android Device Info (use MediaQuery.displayFeaturesOf() instead) Mar 19, 2024
@miquelbeltran miquelbeltran changed the title fix(device_info_plus)!: Remove Display Metrics from Android Device Info (use MediaQuery.displayFeaturesOf() instead) fix(device_info_plus)!: Remove Display Metrics from Android Device Info Mar 19, 2024
Copy link
Collaborator

@vbuberen vbuberen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good that you mentioned about the DisplayFeature API as I wanted to share it as well :)

I am Ok with dropping this data from the plugin.

@ChristianEdwardPadilla
Copy link
Contributor

LGTM. Thanks the quick turnaround on all this!

@miquelbeltran miquelbeltran merged commit c5af332 into main Mar 19, 2024
19 of 21 checks passed
@miquelbeltran miquelbeltran deleted the miquelbeltran/2687-2 branch March 19, 2024 16:27
@alexyuyl
Copy link

Hi, thanks for the work. Personally I used the device metric to obtain Android device physical info as below before the change:

Map<String, dynamic> _readAndroidBuildData(AndroidDeviceInfo build) { return <String, dynamic> { 'displayWidthPixels': build.displayMetrics.widthPx, 'displayWidthInches': build.displayMetrics.widthInches, 'displayHeightPixels': build.displayMetrics.heightPx, 'displayHeightInches': build.displayMetrics.heightInches }; }

This was in hope to accurately replicate physical distance on screen using pixel counts. Now that the plugin no longer support the features, what is the alternative way to obtain the number of pixels in both height and width on a screen, and the actual length and width of the device in real world? Thank you.

@miquelbeltran
Copy link
Member Author

There are packages that implement this functionality, also support all platforms and not just Android. e.g. https://github.com/benthillerkus/millimeters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: device_info_plus violates Android StrictMode's IncorrectContextUseViolation
4 participants