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

type 'Null' is not a subtype of type 'TextSpan' – Flutter

when i run this, i got this error:
type ‘Null’ is not a subtype of type ‘TextSpan’

child: SingleChildScrollView(child: Arguments_text['1']),
italic(String text) {
  TextSpan(
    text: text,
    style: TextStyle(
      fontSize: 17.0,
      fontStyle: FontStyle.italic,
      color: Colors.black,
    ),
  );
}



Map<String, Column> Arguments_text = {
  '1': Column(
    children: [
      RichText(
        text: TextSpan(
          children: <TextSpan>[
            italic('Hello '),
            italic('World'),
          ],
        ),
      )
    ],
  ),
};

Someone know how can i solve this?
Thanks.

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 :

Acoording to https://dart.dev/guides/language/language-tour#return-values:

All functions return a value. If no return value is specified, the
statement return null; is implicitly appended to the function body.

Your italic function implicitly returns null, try this:

TextSpan italic(String text) {
  return TextSpan(
    text: text,
    style: TextStyle(
      fontSize: 17.0,
      fontStyle: FontStyle.italic,
      color: Colors.black,
    ),
  );
}
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