Programming in Dart: Fundamentals · Function Basics | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4921688-programming-in-dart-fundamentals/lessons/20

For the method optional parameter, I tried to use the example from the tutorial:

String fullName(String first, String last, [String title]) {
  return "${title == null ? '': '$title'}$first $last";
}

But got compile error, how comes it was running in the tutorial, dart 2.12.1

Error: The parameter ‘title’ can’t have a value of ‘null’ because of its type ‘String’, but the implicit default value is ‘null’.
Try adding either an explicit non-‘null’ default value or the ‘required’ modifier.