textStyle static method
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,
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);
}