Flutter SafeArea Widget Examples – Avoid the Notch

The notch was introduced first in iPhone X, then was implemented in almost every Android phone. It comes in different shapes and sizes. Programming an app to make it suit different notches is hard. So Google introduced SafeArea widget, which insets its child with sufficient padding to avoid intrusions by the operating system.

The widget can do something like indenting the child by enough to avoid the status bar or a notch at the top of the screen.

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home'),
      ),
      backgroundColor: Colors.white,
      body: SafeArea(
          top: true,
          bottom: true,
          left: true,
          right: true,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Container(
                width: MediaQuery.of(context).size.width,
                height: 300,
                color: Colors.orange,
                child: Text('Container in SafeArea', style: TextStyle(color: Colors.white, fontSize: 26),),
              )
            ],
          )),
    );
  }
}
  • top : Used to avoid system intrusions on top of the screen like the Status bar.
  • bottom : Used to avoid system intrusions on the bottom of the screen.
  • left : Used to avoid system intrusions on the left side of the screen.
  • right : Used to avoid system intrusions on the right side of the screen

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close