I need to decorate input based on some boolean flag.
If flag is On – I need change edge insets.
If flag is Off – I need no changes and want to use current value of contentPadding (instead of ????)
TextField(
decoration: InputDecoration(
contentPadding: someBoolFlagIsOn ? EdgeInsets.zero.copyWith(left: 10) : ????,
How can I do that in ternary operator?
2
Answers
@Artem Zyuzko Please take a moment to review the code below. I think it could be really helpful.
If
someBoolFlagIsOn
is true, it appliesEdgeInsets.zero.copyWith(left: 10)
as the content padding. If false, it uses the current contentPadding value by creating a new InputDecoration and accessing its contentPadding property.Output:
When
someBoolFlagIsOn
is true, or in other words, under the condition thatsomeBoolFlagIsOn
is true.When
someBoolFlagIsOn
is not true, or in other words, when it is false.You could just assign a different decoration without the contentPadding in that case. So like