I get the following error: The argument type 'void Function(String?)' can't be assigned to the parameter type 'void Function()?' when I this in my code:
void openNoteBox(String? docID) {}
...
***onPressed: openNoteBox //Error here***
...
onPressed: () => openNoteBox(docID), // it works here
...
This fixed it:
void openNoteBox({String? docID}) {}
...
***onPressed: openNoteBox, //error is gone here***
...
onPressed: () => openNoteBox(docID: docID),
...
but why would the previous one not work?
In the first code you defined a required positional parameter. To define an optional positional parameter, use this syntax:
From the documentation on optional positional parameters:
In the second code you defined a named parameter, which by default is optional. From the documentation:
Also note that you can't define both named parameters and optional positional parameters. From the documentation on parameters: