ERROR:- The return type 'String' isn't a 'Widget', as required by the closure's context. I need to add the last one-week date in the bottom titles but got an error in the updated version. in the previous version, it's working fine. but now I got this error when ugrade the flutter pub YAML.
SideTitles get bottomTitles {
return SideTitles(
showTitles: true,
getTitlesWidget: (value, meta) {
String text = '';
switch (value.toInt()) {
case 1:
return DateFormat('dd')
.format(DateTime.now().subtract(Duration(days: 6)));
case 2:
return DateFormat('dd')
.format(DateTime.now().subtract(Duration(days: 5)));
case 3:
return DateFormat('dd')
.format(DateTime.now().subtract(Duration(days: 4)));
case 4:
return DateFormat('dd')
.format(DateTime.now().subtract(Duration(days: 3)));
case 5:
return DateFormat('dd')
.format(DateTime.now().subtract(Duration(days: 2)));
case 6:
return DateFormat('dd')
.format(DateTime.now().subtract(Duration(days: 1)));
case 7:
return DateFormat('dd').format(DateTime.now());
}
return '';
},
);
}
CodePudding user response:
Wrap them in Text
, like
return Text(DateFormat('dd')
.format(DateTime.now().subtract(Duration(days: 6))));
It's always a good idea to check the changelog whenever you update a package. See https://pub.dev/packages/fl_chart/changelog
Especially the BREAKING changes. The issue you are having is because of the changes in 0.50.0