Home > Enterprise >  type 'Null' is not a subtype of type 'TextSpan' - Flutter
type 'Null' is not a subtype of type 'TextSpan' - Flutter

Time:11-18

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.

CodePudding user response:

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