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

71 views Asked by At

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.

1

There are 1 answers

0
void void On BEST ANSWER

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