Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

A value of type 'TextSpan' can't be returned from the method 'build' because it has a return type of 'Widget'

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();
  }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading