textStyle static method

TextStyle textStyle({
  1. TextStyle baseStyle = const TextStyle(),
  2. required Color color,
  3. required int depth,
  4. Curvature curvature = Curvature.flat,
  5. Swell swell = Swell.emboss,
  6. double spread = 5,
  7. AlignmentGeometry lightSource = defaultLightSource,
  8. Rect? gradientRect,
  9. TextDirection? textDirection,
})

Build a Neumorphic TextStyle that begins with baseStyle.

The baseStyle defaults to an empty TextStyle and is offered as a convenience parameter. This base style will be returned, copied with neumorphic decorations.

If a Rect is provided as gradientRect, then a gradient shader is generated for this TextStyle (instead of only a color) to paint atop the glyphs.

  • Also then consider the textDirection as it will not be obtained by this static method automatically.

Implementation

static TextStyle textStyle({
  TextStyle baseStyle = const TextStyle(),
  required Color color,
  required int depth,
  Curvature curvature = Curvature.flat,
  Swell swell = Swell.emboss,
  double spread = 5,
  AlignmentGeometry lightSource = defaultLightSource,
  Rect? gradientRect,
  TextDirection? textDirection,
}) {
  final direction = textDirection ?? TextDirection.ltr;
  final paint = Paint();
  if (gradientRect != null) {
    paint.shader = linearGradient(
      color: color,
      curvature: curvature,
      swell: swell,
      depth: depth,
      begin: lightSource.resolve(direction),
    ).createShader(gradientRect, textDirection: direction);
  }
  final style = baseStyle.copyWith(
    color: color.withBlack(depth ~/ swell.divisor(depth) - 1),
    shadows: boxShadows(
      color: color,
      curvature: curvature,
      swell: swell,
      depth: depth,
      spread: spread,
      lightSource: lightSource.resolve(direction),
      offsetScalar: 0.6,
    ),
  );
  return (paint.shader == null) ? style : style.copyWith(foreground: paint);
}