Want to set default value in function? The syntax you use is correct, but as the error message says, the value has to be a compile time constant. A compile time constant doesn’t make sense for DateTime.now().
As a workaround, you can use:
1 2 3 4 5 6 7 8 9 | /// Returns `true` is still going on. /// /// [date] the date to check. /// as default value `DateTime.now()` is used /// if no value or `null` was passed. bool isOnGoing([DateTime date]) { date ??= DateTime.now(); ... } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.