I want to create a function that calculates expense total and income total based on the provided month, and if a year is not provided, it should calculate based on the current year.
So I want to give the default value to the current year, but it's showing error.
I want to create a function that calculates expense total and income total based on the provided month, and if a year is not provided, it should calculate based on current year.
So I want to give the default value to the current year, but it shows an error at design time:
Map<String, dynamic> monthBalanceCard({required int month, int year=DateTime.now().year}) { final expenseTransactions = _allTransactions .where((element) => element.isexpense) .toList() .where((element) => element.date.year == year && element.date.month == month); final incomeTransactions = _allTransactions .where((element) => element.isexpense = false) .toList() .where((element) => element.date.year == year && element.date.month == month); double expenseTotal = expenseTransactions.fold( 0, (previousValue, element) => previousValue + element.amount); double incomeTotal = expenseTransactions.fold( 0, (previousValue, element) => previousValue + element.amount); double balance = expenseTotal - incomeTotal; return {'Expense': expenseTotal,'Income': incomeTotal,'Balance': balance, }; }