I'm refactoring a Flutter app for readability, and decided to reduce duplication by moving repeated calls to wrap a widget with Padding by extracting a method. The method looks like this:
Padding _wrapWithPadding(Widget widget, {double horizontal = 8.0, double vertical = 0.0}) {
return const Padding(padding:
EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical),
child: widget);
}
The Dart compiler complains that horizontal, vertical, and widget arguments are not const on the call to the Padding constructor. I understand the problem, but surely there is a way to accomplish removing the duplication of creating a Padding element over and over again?
Is there someway to get the compiler to treat those values as const, or is there another way to accomplish my goal?