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

Wrong device type recognized #14

Open
xxjonesriderxx opened this issue Jun 23, 2021 · 1 comment
Open

Wrong device type recognized #14

xxjonesriderxx opened this issue Jun 23, 2021 · 1 comment

Comments

@xxjonesriderxx
Copy link

xxjonesriderxx commented Jun 23, 2021

This library returns

deviceIsTablet=false

on a bunch of tablets. This error does not occur every time, but it does happen again and again.

It also rarely happens in debug mode but mostly in release mode.

Tested devices: iPad mini, iPad Air 2, Galaxy Tab S6, Galaxy Tab A2

@xxjonesriderxx
Copy link
Author

Solved the problem. If your doing something like this in your main:

SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft]).then((_) {runApp(MaterialApp())}

you should create and keep an reference to Device.get().isTablet after the device orientation was successful set.

SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft]).then((_) { runApp(MaterialApp()); codeRunningOnTabletReference = Device.get().isTablet; }

Then you can access this reference everywhere in your app to know if your code is running on a tablet or smartphone.
Do never ever call Device.get().isTablet each time you need it. Just create an reference to it in main() after you changed your screen orientation or other ui related pre settings. This library sometime changes the detected device type while running the app. Its only like 95% accurate.

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

No branches or pull requests

1 participant