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

Time:07-08

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.

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

CodePudding user response:

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()

  • Related