Use SafeArea Widget in Flutter to protect the UI from being covered by system overlays such as navigation bars, status bars, and other platform-specific features.
SafeArea protects the UI from
- Navigation Bar: When a navigation bar is present at the bottom of the screen,
SafeArea
ensures that your UI content doesn’t get covered by it. - Status Bar: When a status bar is present at the top of the screen,
SafeArea
ensures that your UI content doesn’t get covered by it. - Notch: On devices with a notch (like the iPhone X or later),
SafeArea
ensures that your UI content doesn’t get cut off by the notch. - System overlays:
SafeArea
also protects against other system overlays like the keyboard, which can cover parts of your UI when a text input field is focused. - Platform-specific features:
SafeArea
takes into account platform-specific features like the home indicator on iOS devices, which can cover parts of your UI.
By using SafeArea
, you can ensure that your UI content is not hidden and inaccessible to touches.
Example
Here’s an example of how to use SafeArea
in Flutter:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Text('Hello, World!'),
),
),
);
}
}
In this example, the SafeArea
widget ensures that the text is always visible and not covered by any system overlays or platform-specific features. For more hints – check out more articles on https://programtom.com/dev/category/software-development/flutter/