I have the following widget
import 'dart:collection';
import 'package:flutter/material.dart';
@immutable
class StrokeText extends StatelessWidget {
final String text;
final Color color;
final Color strokeColor;
final double strokeWidth;
final TextStyle? style;
final TextOverflow? overflow;
const StrokeText(
this.text, {
Key? key,
this.color = Colors.white,
this.strokeColor = Colors.black,
this.strokeWidth = 1,
this.style,
this.overflow,
}) : super(key: key);
List<Shadow> outlinedText({
double strokeWidth = 2,
Color strokeColor = Colors.black,
int precision = 5,
}) {
Set<Shadow> result = {};
for (int x = 1; x < strokeWidth + precision; x++) {
for (int y = 1; y < strokeWidth + precision; y++) {
double offsetX = x.toDouble();
double offsetY = y.toDouble();
result.add(Shadow(offset: Offset(-strokeWidth / offsetX, -strokeWidth / offsetY), color: strokeColor));
result.add(Shadow(offset: Offset(-strokeWidth / offsetX, strokeWidth / offsetY), color: strokeColor));
result.add(Shadow(offset: Offset(strokeWidth / offsetX, -strokeWidth / offsetY), color: strokeColor));
result.add(Shadow(offset: Offset(strokeWidth / offsetX, strokeWidth / offsetY), color: strokeColor));
}
}
return result.toList();
}
@override
Widget build(BuildContext context) {
return Text(
text,
overflow: overflow,
style: TextStyle(
fontSize: style?.fontSize,
fontWeight: style?.fontWeight,
fontFamily: style?.fontFamily,
height: style?.height,
wordSpacing: style?.wordSpacing,
color: color,
shadows: outlinedText(
strokeColor: strokeColor,
strokeWidth: strokeWidth,
),
),
);
}
}
Which displays shadows behind text, which works great. But once the text overflows the shadow will only be on the elipsis. Does anyone know why this happens?
