Getter functions are functions that retrieve something and have no arguments.

 

syntax:

returnType get NameOfFunction { return code }

 

Let's define an objective so we can walk through an example:

I want to get a list of maps that has the day as a key and the amount as value over the last 7 days.

{'day': DateFormat.E().format(weekday), 'amount': totalSum}

I want to return a List<Map<String, Object>>

then I define my getter: 

List<Map<String, Object>> get groupedTransaction {} where groupedTransaction is the name of my getter function.

I want to have a list of the last 7 days so I use List.generate() to get a list of a particualr range

 

 List<Map<String, Object>> get groupedTransaction {
    return List.generate(7, (index) {
      final weekday = DateTime.now().subtract(Duration(days: index));
      double totalSum = 0.0;

      for (var i = 0; i < recentTransactions.length; i++) {
        if (recentTransactions[i].date.day == weekday.day &&
            recentTransactions[i].date.month == weekday.month &&
            recentTransactions[i].date.year == weekday.year) {
          totalSum += recentTransactions[i].amount;
        }
      }
      print(DateFormat.E().format(weekday));
      print(totalSum);
      return {'day': DateFormat.E().format(weekday), 'amount': totalSum};
    });
 }