-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add example for locking screen orientation in a letterboxing environment #131266
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
Conversation
zanderso
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
| /// class OrientationLockingObserver extends WidgetsBindingObserver { | ||
| /// @override | ||
| /// void didChangeMetrics() { | ||
| /// final ui.Display display = PlatformDispatcher.instance.implicitView!.display; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is making a single view assumption that we worked so hard on to remove from the framework. What if implicitView is null? Any way we can make this look up the actual view things are getting rendered into? From a widget tree you can use View.of, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have a widget tree in an observer, and right now the media query doesn't give you access to the display. I was going to hold off on that until it's implemented on at least Windows (right now it's only on Android, iOS, and macOS).
Are we expecting multi-window on Android to be a thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have a widget tree in an observer,
An observer can be anything, including something that is in the widget tree, e.g. a State object.
Are we expecting multi-window on Android to be a thing?
Multi-view will be a thing on Android, e.g. in add-to-app scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've updated the sample code to make a stateful widget that listens to the right view now, and happened to notice a bug in another semi-related sample which I fixed up.
| /// WidgetsBinding.instance.removeObserver(this); | ||
| /// WidgetsBinding.instance.addObserver(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only have to happen once in initState?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yes. Then I don't need the remove/add...
| /// return const MaterialApp( | ||
| /// home: Placeholder(), | ||
| /// ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the widget maybe just take a child that's returned here? (not feel super strongly about this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that this widget would be your root application widget. You'd only want one of these in the tree.
| /// // into which this widget is drawn. | ||
| /// _lastSize = View.of(context).physicalSize; | ||
| /// WidgetsBinding.instance.removeObserver(this); | ||
| /// WidgetsBinding.instance.addObserver(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The add should stay in initState, and no need to remove it in didChangeDependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
goderbauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thanks for fixing up the other example as well! |
flutter/flutter@9def8f6...bae1ac2 2023-07-26 [email protected] ImageDecoration.lerp (flutter/flutter#130533) 2023-07-26 [email protected] Document the Flow/Opacity/hit-test issues (flutter/flutter#131239) 2023-07-26 [email protected] Run benchmarks with `--omit-type-checks` (flutter/flutter#131102) 2023-07-26 [email protected] Roll Flutter Engine from ba83c144f84e to faf1121d010c (2 revisions) (flutter/flutter#131339) 2023-07-26 [email protected] Roll Packages from 406eac1 to a99fc87 (1 revision) (flutter/flutter#131336) 2023-07-26 [email protected] [flutter roll] Revert "Fix floating SnackBar throws when FAB is on the top" (flutter/flutter#131303) 2023-07-26 [email protected] Roll Flutter Engine from 89203002f455 to ba83c144f84e (1 revision) (flutter/flutter#131329) 2023-07-26 [email protected] Roll Flutter Engine from b3cd1c599abe to 89203002f455 (1 revision) (flutter/flutter#131323) 2023-07-26 [email protected] Roll Flutter Engine from 4bdceccff964 to b3cd1c599abe (1 revision) (flutter/flutter#131317) 2023-07-26 [email protected] Roll Flutter Engine from df12fff329a1 to 4bdceccff964 (2 revisions) (flutter/flutter#131316) 2023-07-26 [email protected] Roll Flutter Engine from 43f727e4748a to df12fff329a1 (3 revisions) (flutter/flutter#131314) 2023-07-26 [email protected] Roll Flutter Engine from 7f3b0d6b7250 to 43f727e4748a (1 revision) (flutter/flutter#131311) 2023-07-26 [email protected] Roll Flutter Engine from db711f14842b to 7f3b0d6b7250 (4 revisions) (flutter/flutter#131309) 2023-07-26 [email protected] Reorders menu item button shortcuts on Mac-like platforms (flutter/flutter#129309) 2023-07-26 [email protected] Roll Flutter Engine from 9e00c11eb519 to db711f14842b (3 revisions) (flutter/flutter#131307) 2023-07-26 [email protected] Ignore unused parameters in snippet code (flutter/flutter#131068) 2023-07-25 [email protected] Roll Flutter Engine from 3fff7316dc8d to 9e00c11eb519 (1 revision) (flutter/flutter#131299) 2023-07-25 [email protected] Add example for locking screen orientation in a letterboxing environment (flutter/flutter#131266) 2023-07-25 [email protected] Update BottomAppBar and BottomAppBarTheme tests for M3 (flutter/flutter#130983) 2023-07-25 [email protected] Roll Flutter Engine from f5fbfa859b63 to 3fff7316dc8d (4 revisions) (flutter/flutter#131286) 2023-07-25 [email protected] Add Sabin Neupane to AUTHORS (flutter/flutter#131237) 2023-07-25 [email protected] Roll Packages from 8028caf to 406eac1 (4 revisions) (flutter/flutter#131285) 2023-07-25 [email protected] Roll Flutter Engine from 0a5c6cdd5d02 to f5fbfa859b63 (8 revisions) (flutter/flutter#131283) 2023-07-25 [email protected] 🚀 Expose `scrollControlDisabledMaxHeightRatio` to the modal bottom sheet (flutter/flutter#129688) 2023-07-25 [email protected] Revert "Proposal to add barrier configs for showDatePicker, showTimePicker and showAboutDialog." (flutter/flutter#131278) 2023-07-25 [email protected] Roll Flutter Engine from 036c58f79307 to 0a5c6cdd5d02 (1 revision) (flutter/flutter#131256) 2023-07-25 [email protected] Fix `RawChip` doesn't use `ChipTheme.showCheckmark` value (flutter/flutter#131257) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…ent (flutter#131266) Android may choose to letterbox applications that lock orientation. This gets particularly bad on foldable devices, where a developer may want to lock orientation when the devices is folded and unlock when unfolded. However, if the app is letterboxed when unfolded, the `MediaQuery.of(context).size` will never report the full display size, only the letterboxed window size. This may result in an application getting "stuck" in portrait mode. /cc @TytaniumDev
…ent (flutter#131266) Android may choose to letterbox applications that lock orientation. This gets particularly bad on foldable devices, where a developer may want to lock orientation when the devices is folded and unlock when unfolded. However, if the app is letterboxed when unfolded, the `MediaQuery.of(context).size` will never report the full display size, only the letterboxed window size. This may result in an application getting "stuck" in portrait mode. /cc @TytaniumDev
Android may choose to letterbox applications that lock orientation. This gets particularly bad on foldable devices, where a developer may want to lock orientation when the devices is folded and unlock when unfolded. However, if the app is letterboxed when unfolded, the
MediaQuery.of(context).sizewill never report the full display size, only the letterboxed window size. This may result in an application getting "stuck" in portrait mode./cc @TytaniumDev