I am using this code to get the aspect ratio
final deviceAspectRatio = View.of(context).physicalSize.aspectRatio;
It gives correct result in portrait but when I change the orientation in landscape and run same code I get different result. I found that width and height get flipped in orientation change so I tried
final size = View.of(context).physicalSize;
final deviceAspectRatio = isPortrait ? size.width / size.height : size.height / size.width;
but still they are not same. How can I get correct and same aspect ratio or resolution for both orientation ?
2
Answers
I found the solution. Actually in landscape mode width changes because of notch and navigation bar. So we need to use display features to get the difference.
Try using the flipped getter on physicalSize.
The aspectRatio is not exactly the same, but it is pretty close.