I need to create a custom SpanText, but i found this issue.
A value of type ‘TextSpan’ can’t be returned from the method ‘build’ because it has a return type of ‘Widget’.
The Code Is:
class StareWidget extends StatelessWidget {
const StareWidget({Key? key, required this.text}) : super(key: key);
final String text;
@override
Widget build(BuildContext context) {
return TextSpan();
}
}
>Solution :
According to documentation
To paint a TextSpan on a Canvas, use a TextPainter. To display a text span in a widget, use a RichText. For text with a single style, consider using the Text widget.
So your TextSpan needs to have a RichText as parent.