Device with HomeBar need some spacing on the bottom of the page. So, we need to check if device has homebar so that we can give the padding accordingly.
You can use the SafeArea widget to easily wrap your content and avoid the bottom insets.
To actually get the size, you can use MediaQuery.of(context).viewInsets and check its bottom insets. (You do not need to do this, if you just want to add padding. Use SafeArea like I mentioned above.)
You can use MediaQuery.of(context).padding.bottom and perform a certain action if it is non-zero. For example
if (MediaQuery.of(context).padding.bottom > 0) {
// homebar is present
} else {
// homebar is not present
}
Or you can use MediaQuery.of(context).viewInsets.bottom. Both MediaQuery.of(context).padding.bottom and MediaQuery.of(context).viewInsets.bottom will give you the same result, but using viewInsets.bottom is more accurate since it takes into account any system UI elements that may be present, such as the keyboard, not just the home bar.
3
Answers
You can use the
SafeArea
widget to easily wrap your content and avoid the bottom insets.To actually get the size, you can use
MediaQuery.of(context).viewInsets
and check its bottom insets. (You do not need to do this, if you just want to add padding. UseSafeArea
like I mentioned above.)You can use
MediaQuery.of(context).padding.bottom
and perform a certain action if it is non-zero. For exampleOr you can use
MediaQuery.of(context).viewInsets.bottom
. BothMediaQuery.of(context).padding.bottom
andMediaQuery.of(context).viewInsets.bottom
will give you the same result, but usingviewInsets.bottom
is more accurate since it takes into account any system UI elements that may be present, such as the keyboard, not just the home bar.A widget that insets its child by sufficient padding to avoid intrusions by the operating system.
For example, this will indent the child by enough to avoid the status bar at the top of the screen.
It will also indent the child by the amount necessary to avoid The Notch on the iPhone X, or other similar creative physical features of the display.
When a minimum padding is specified, the greater of the minimum padding or the safe area padding will be applied.