Home > Software engineering >  fl_chart want to add last one week dates in bottomTitles in lineChart
fl_chart want to add last one week dates in bottomTitles in lineChart

Time:09-14

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.

enter image description here

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

enter image description here

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

  • Related