Search code examples
flutterflutter-layoutpadding

Conditional padding inside Flutter widget


I see this answer for conditional color

I am trying to do the same for padding like so

Padding(
  padding: const EdgeInsets.only(bottom: isLogin ? 58.0 : 10.0),
)

it is not being accepted.

Thank you


Solution

  • You can use it like this:

                padding: isLogin
                    ? EdgeInsets.only(bottom: 58.0)
                    : EdgeInsets.only(bottom: 10.0),
    

    Edit:

    or just remove const like this.

                padding: EdgeInsets.only(bottom: isLogin ? 58.0 : 10.0),
    

    You can read the usage of const from here.