ImageStyle constructor
const
ImageStyle({})
Creates an ImageStyle configuration for consistent image display.
The fit controls how the image scales within its bounds, defaulting to BoxFit.contain
to preserve aspect ratio without cropping. Width and height default to double.infinity
for flexible sizing based on parent constraints. color and colorBlendMode enable
overlay effects, such as darkening or tinting, while alignment positions the image
within available space, defaulting to center.
Initialization ensures invalid fits (scaleDown, none) are asserted against to maintain display integrity. Use named parameters for clarity in complex UIs.
Implementation
const ImageStyle(
{this.fit = BoxFit.contain,
this.width = double.infinity,
this.height = double.infinity,
this.color,
this.colorBlendMode,
this.alignment})
: assert(fit != BoxFit.scaleDown,
"Fit cannot be scaleDown. Use contain instead."),
assert(fit != BoxFit.none, "Fit cannot be none. Use contain instead.");