Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

Why is it showing an error when setting default argument value with the current year in Flutter?

$
0
0

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

Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>