Skip to content

Conversation

@abbashosseinii
Copy link
Contributor

@abbashosseinii abbashosseinii commented Oct 12, 2025

This PR fixes several orientation-related issues by refactoring the orientation detection
on Android.

Changes:

  • Android: Replaced the BroadcastReceiver for ACTION_CONFIGURATION_CHANGED with an
    OrientationEventListener to get the physical device orientation instead of the UI
    orientation.
  • Overlay: The BarcodePainter now receives the deviceOrientation and adjusts the
    cameraPreviewSize accordingly, fixing the barcode overlay alignment on orientation
    change.
  • Version: Bumped version to 7.1.3.

Related Issues:

Fixes #1486
Fixes #1474
Fixes #1462

Copy link
Collaborator

@navaronbracke navaronbracke left a comment

Choose a reason for hiding this comment

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

Overall this is LGTM, except for one question on iOS.

Also, this needs a changelog entry.

}

return videoOrientation
return UIDevice.current.orientation.videoOrientation
Copy link
Collaborator

@navaronbracke navaronbracke Oct 14, 2025

Choose a reason for hiding this comment

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

UIDeviceOrientation doesn't have a videoOrientation member?

https://developer.apple.com/documentation/uikit/uidevice/orientation

Or am I looking in the wrong place?

Isn't this the old switch case above? And what with the old comment:

// Get the orientation from the window scene if available
// When the app's orientation is fixed and the app orientation is actually different from the device orientation, it malfunctions.

does that still apply?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the thorough review and the LGTM—much appreciated!
Regarding your question on the iOS orientation handling: I've reverted those changes in this commit because I don't have access to physical iOS devices to fully test the UIDeviceOrientation logic and ensure it aligns with the window scene fallback (or avoids the issues noted in the old comment). I was only able to verify the fixes on Android, so I'd prefer to hold off on iOS until I can test properly or get some guidance/eyes on it from the team.
If you'd like to take a stab at refining that part (or point me to the right approach for the videoOrientation mapping), I'm all ears—happy to iterate! Otherwise, let me know if this works for merging the Android-focused fixes as-is.
(Added a changelog entry for the Android refactors)

@FelipeABastos
Copy link

Nice one! Any estimate on when this will be merged?

@juliansteenbakker
Copy link
Owner

@FelipeABastos I have a very busy week this week, so i'm aiming for next week.

- Add flutter/services.dart import for DeviceOrientation enum
- Update all BarcodePainter constructor calls to include required deviceOrientation parameter
- Set deviceOrientation to DeviceOrientation.portraitUp for all test cases
- Fixes compilation errors after BarcodePainter constructor was updated to require deviceOrientation

All 6 tests now pass successfully.
- Refactored Android orientation detection to use `OrientationEventListener`, improving accuracy during `MobileScanner` initialization.
- Updated `BarcodePainter` to dynamically adjust `cameraPreviewSize` based on `deviceOrientation`, resolving overlay misalignment during device rotations.
As with official 1P plugins, these also don't use a header for the changelog, so I removed that here, too.

For example: 
https://github.com/flutter/packages/blob/main/packages/camera/camera/CHANGELOG.md
Copy link
Collaborator

@navaronbracke navaronbracke left a comment

Choose a reason for hiding this comment

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

LGTM!

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 38.45%. Comparing base (9667f6d) to head (1bbfcd4).

Files with missing lines Patch % Lines
lib/src/overlay/barcode_overlay.dart 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1552      +/-   ##
===========================================
+ Coverage    38.14%   38.45%   +0.31%     
===========================================
  Files           42       42              
  Lines          991      996       +5     
===========================================
+ Hits           378      383       +5     
  Misses         613      613              
Flag Coverage Δ
unittests 38.45% <88.88%> (+0.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@navaronbracke navaronbracke left a comment

Choose a reason for hiding this comment

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

One more thing, it seems that one of the files was not formatted, using the 80 character line length limit:

   info • The line length exceeds the 80-character limit • lib/src/overlay/barcode_painter.dart:61:81 • lines_longer_than_80_chars
   info • The line length exceeds the 80-character limit • lib/src/overlay/barcode_painter.dart:73:81 • lines_longer_than_80_chars

@abbashosseinii
Copy link
Contributor Author

Also fixed a couple of long-line lints in the painter for good measure.

@navaronbracke navaronbracke merged commit 61b2f8a into juliansteenbakker:develop Oct 18, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants