Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I change the original code to always add `top: false` in my SafeArea widget?

I wanted to use "statusBarColor: Colors.transparent", on all views, I can do this with ThemeData besides, I have to use SafeArea(top: false,) like this, yeah this is a solution but I have to use SafeArea(top: false) on all view,

 Widget build(BuildContext context) {
    return SafeArea(
      top: false,
.........

enter image description here

I didn’t find any solution with ThemeData, so I was either going to use it on all views I have or I was going to change the original code(safe_area.dart). If I do, this is what I want and this fits perfectly in my situation.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

question => to change original code is bad idea ? or good idea ? in what case should we do this, or should we do it?
enter image description here

>Solution :

To always add top: false whenever you call a SafeArea(),
you can create your own class that extends SafeArea:

class mySafeArea extends SafeArea {
   Widget child;

  mySafeArea({
    Key? key,
    required this.child,
  }) : super(
            key: key,
            child: child,
            top: false,
            bottom: true,
            left: true,
            right: true,
            minimum: const EdgeInsets.all(0),
            maintainBottomViewPadding: false);
  @override
  Widget build(BuildContext context) {
    return SafeArea(child: child);
  }
}

Then call mySafeArea() instead of SafeArea()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading