'Jetpack Compose - Wrong dimension of device

When I write this code:

val widthScreenDp = LocalConfiguration.current.screenWidthDp
val heightScreenDp = LocalConfiguration.current.screenHeightDp
val widthScreenPx = with(LocalDensity.current) { widthScreenDp.dp.toPx() }
val heightScreenPx = with(LocalDensity.current) { heightScreenDp.dp.toPx() }

For my Xiaomi mi10, the result is 1078 by 2117.5 instead of 1080 by 2340 For the Pixel5 emulator 1078 by 2062...

What is the problem ? How to have complete dimension of the device on Jetpack Compose ?

it looks like it lacks the status/nav bars heights.

Thank you !



Solution 1:[1]

This is the official explain for screenHeightDp:

The current height of the available screen space, in dp units, corresponding to screen height resource qualifier.

Maybe status/nav bars is not available spaces.

You can get screen height like that:

BoxWithConstraints {
   val screenHeight = maxHeight
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 oMMiao