setImageAssetsIcon method

Widget setImageAssetsIcon({
  1. required String name,
  2. Color color = Colors.black,
  3. BoxFit? boxFit,
  4. double width = 20,
  5. double height = 20,
  6. double padding = 8.0,
})

Creates a padded image widget from assets with customizable styling.

Displays an asset image with configurable dimensions, color tint, fit mode, and padding.

Parameters:

  • name: Path to the asset image.
  • color: Tint color applied to the image (defaults to black).
  • boxFit: How the image should be inscribed into the space. Defaults to BoxFit.scaleDown.
  • width: Image width (defaults to 20).
  • height: Image height (defaults to 20).
  • padding: Padding around the image (defaults to 8.0).

Returns a Padding widget containing the asset image.

Example:

setImageAssetsIcon(
  name: 'assets/icons/star.png',
  color: Colors.yellow,
  width: 24,
  height: 24,
  boxFit: BoxFit.contain,
);

Implementation

Widget setImageAssetsIcon(
    {required String name,
    Color color = Colors.black,
    BoxFit? boxFit,
    double width = 20,
    double height = 20,
    double padding = 8.0}) {
  return Padding(
    padding: EdgeInsets.all(padding),
    child: Image.asset(
      name,
      height: height,
      width: width,
      color: color,
      fit: boxFit ?? BoxFit.scaleDown,
    ),
  );
}