type 'int' is not a subtype of type 'String' error in Dart
title: new Text(time ?? "Empty"),
should be
title: new Text(time != null ? '$time' : "Empty"),
or
title: new Text('${time ?? "Empty"}'),
The code in following line from your snippet is:
title: new Text(time ?? "Empty"),
While, it should actually look like following:
title: new Text(time?.toString() ?? "Empty"),
As the above answers pointed, the time
variable was int
while the Text()
required an String
.
There might be another issue:
If the time
was null
, the null-aware operator ??
will not work as expected. Because the time
variable was used before the ??
in time *= 1000
expression.
Therefore, the time *= 1000
should be deleted, and the Text
should be like
Text(time == null ? "Empty" : '${time * 1000}')
Note: The time
was not modified in this case.