icon method

Widget icon({
  1. IconParkProps? props,
  2. IconParkThemeType? theme,
  3. double? strokeWidth,
  4. StrokeJoin? strokeLineJoin,
  5. StrokeCap? strokeLineCap,
  6. double? size,
  7. Color? outStrokeColor,
  8. Color? outFillColor,
  9. Color? innerStrokeColor,
  10. Color? innerFillColor,
  11. bool? applyTextScaling,
  12. String? semanticLabel,
})

Implementation

Widget icon({
  IconParkProps? props,
  IconParkThemeType? theme,
  double? strokeWidth,
  StrokeJoin? strokeLineJoin,
  StrokeCap? strokeLineCap,
  double? size,
  Color? outStrokeColor,
  Color? outFillColor,
  Color? innerStrokeColor,
  Color? innerFillColor,
  bool? applyTextScaling,
  String? semanticLabel,
}) {
  return Builder(
    builder: (context) {
      props ??= IconParkProps.maybeOf(context);
      if (props == null) {
        final parkTheme = Theme.of(context).extension<IconParkTheme>();
        theme ??= parkTheme?.defaultTheme ?? IconParkThemeType.outline;
        props = parkTheme?.paletteMap[theme];
        props ??= IconParkProps.fromColorScheme(
          Theme.of(context).colorScheme,
          theme!,
        );
      }
      final iconTheme = IconTheme.of(context);
      if (iconTheme.color != null) {
        props = props!.copyWithColor(outStrokeColor: iconTheme.color!);
      }
      size ??= iconTheme.size ?? kDefaultFontSize;

      applyTextScaling ??= iconTheme.applyTextScaling ?? false;

      final double? iconSize =
          applyTextScaling!
              ? MediaQuery.textScalerOf(context).scale(size!)
              : size;

      props = props!.copyWithColor(
        outStrokeColor: outStrokeColor,
        outFillColor: outFillColor,
        innerStrokeColor: innerStrokeColor,
        innerFillColor: innerFillColor,
        strokeWidth: strokeWidth,
        strokeLineJoin: strokeLineJoin,
        strokeLineCap: strokeLineCap,
      );
      double opacity = iconTheme.opacity ?? 1.0;
      opacity = opacity * props!.color1.a;
      Widget icon = SvgPicture.string(
        builder(props!),
        width: iconSize,
        height: iconSize,
        colorFilter:
            opacity < 1.0
                ? ColorFilter.mode(
                  Colors.black.withValues(alpha: opacity),
                  BlendMode.dstIn,
                )
                : null,
        matchTextDirection: matchTextDirection,
      );
      // if (opacity < 1.0) {
      //   icon = Opacity(opacity: opacity, child: icon);
      // }
      if (semanticLabel != null) {
        icon = Semantics(
          label: semanticLabel,
          child: ExcludeSemantics(child: icon),
        );
      }
      return icon;
    },
  );
}