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

[WIP] Device orientation #1716

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

[WIP] Device orientation #1716

wants to merge 4 commits into from

Conversation

TheNoumanDev
Copy link
Member

No description provided.

@TheNoumanDev TheNoumanDev changed the title Device orientation [WIP] Device orientation Nov 5, 2024
MediaQueryCapability,
LocationCapability,
DeviceInfoCapability {
class Device with Invokable, MediaQueryCapability, LocationCapability, DeviceInfoCapability, WidgetsBindingObserver {
Copy link
Contributor

Choose a reason for hiding this comment

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

Setup your formatter to property format code so it is consistent with everyone else. Your review reformats a lot of the code and it shows more changes than needed

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, i do keep the necesarry changes, it was a draft that's why there comments in it as well, Thanks for pointing out.

@@ -98,6 +98,20 @@ class DataContext implements Context {
if (_contextMap['device'] == null) {
_contextMap['device'] = Device();
}

// Always set up the listener
print('👂 Setting up device update listener...');
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't make sense. What is it for? DataContext already points to Device class which handle listening for changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated!

static Stream<MediaQueryData> get onDeviceUpdate => _deviceUpdateController.stream;

Device._internal() {
if (!_isInitialized) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Device is a singleton, meaning there's only 1 instance of it. You don't need to check if it's initialized or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated!

void didChangeMetrics() {
print('📏 Metrics changed - handling update...');
if (!_isHandlingChange) {
WidgetsBinding.instance.addPostFrameCallback((_) => _handleMediaQueryChange());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do addPostFrameCallback() here for? Just call handleMediaqueryChange() directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was to make sure that values gets updated properly, wot was happening before:

  • when I move from portrait to landscape, value was still portrait.
  • and when I again moved back to portrait from landscape, then value updated to portrait and so on.
    it was fixed using addPostFrameCallback()

@override
void didChangeMetrics() {
print('📏 Metrics changed - handling update...');
if (!_isHandlingChange) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this flag for, preventing multiple concurrent call? There is no async code here so that's not going to happen.


// Broadcast the change
print('📢 Broadcasting device update...');
_deviceUpdateController.add(newData);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? Why don't you set the orientation/width/height directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated!

}
}

bool _hasSignificantChanges(MediaQueryData? oldData, MediaQueryData newData) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you use this for testing but why not just remove this function and change it to "orienttation != newData.orientation || size != newData.size". Simpler and less code to look through

@TheNoumanDev TheNoumanDev requested review from vusters and snehmehta and removed request for vusters November 8, 2024 17:33
@kmahmood74
Copy link
Collaborator

@snehmehta please review this

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.

4 participants