I'm new at Dart and I'm taking a course but I don't know if I'm doing something wrong at this particular lesson. I have almost the exact code as my instructor, yet I get an Error instead of a "null" result. This is the code:
import 'package:hello_dart/hello_dart.dart' as hello_dart; // we can also add exceptions on the parameters using "[]" // void main(List<String> arguments) { var name = sayHello("Pink", "Unicorn"); print(name); } String sayHello(String name, String lastName, [int age]) => "$name " "$lastName $age"; The idea of this lesson is to create exceptions on the function's parameters. On this example, he adds [] on "int age" to add an exception and erases "$age". With that he gets "Pink Unicorn null" as a result.
But I get instead this error:
The parameter 'age' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'. Try adding either an explicit non-'null' default value or the 'required' modifier. String sayHello(String name, String lastName, [int age]) ^^^
The course is at least four years old, so maybe there was an update where Dart no longer gives a "null" result to an "int" value ? or am I doing something wrong ? https://prnt.sc/cq-YmQgPVx1R