toSkeletonLine method

Widget toSkeletonLine({
  1. SkeletonConfig? config,
  2. double? width,
  3. double? widthFactor = 0.8,
})

Creates a skeleton line matching this text's style.

Implementation

Widget toSkeletonLine({
  SkeletonConfig? config,
  double? width,
  double? widthFactor = 0.8,
}) {
  final effectiveConfig = config ?? SkeletonConfig.defaultConfig;

  // Estimate height from style
  final height = style?.fontSize ?? 16.0;

  // Use provided width or calculate from factor
  double? effectiveWidth = width;
  if (effectiveWidth == null && widthFactor != null && data != null) {
    // Rough estimate: 0.6 * fontSize per character
    final estimatedFullWidth = data!.length * (style?.fontSize ?? 16) * 0.6;
    effectiveWidth = estimatedFullWidth * widthFactor;
  }

  return SkeletonLine(
    config: effectiveConfig,
    width: effectiveWidth,
    height: height,
  );
}