I'm trying to print forecast.dart, but I'm getting 'instance of WeatherData' printed out. I added @override String toString()
but no changes.. I'm not quite sure why forecast.dart is not printed out.. please help!
How can I fix instance of 'class name' printed out Flutter
1.8k views Asked by Kim At
2
There are 2 answers
0

You need to implement toString
. For example, you could do it like this:
@override
String toString() => 'Weather for ${placeName ?? 'unknown'}';
Alternatively, you could use https://pub.dev/packages/freezed. It automatically generates useful functions (such as fromJson
, toJson
, toString
) for you. You'll save a lot of time this way.
You need to actually add an implementation.
return
the string you want to see when it prints.