Dart required parameters are the arguments that are passed to a function and the function or method required all those parameters to complete its code block.
Functions have already been explained. Now we are going in depth to understand every concept related to functions. Let’s take an example of Dart required parameter function’s code. Let’s print the name of favourite cities.
void main() { favCities('Munich', 'Lahore', 'Lisbon'); } void favCities(String name1, String name2, String name3) { print('First fav city name is $name1'); print('Second fav city name is $name2'); print('Third fav city name is $name3'); }
The output result is
First fav city name is Munich Second fav city name is Lahore Third fav city name is Lisbon
If any of the argument is remove the compiler will generate NoSuchMethodError or Error: Too few positional arguments: 3 required, 2 given.
Since all the parameters are needed that is why it is called the required parameter function. It is all from Dart Required Parameters.
It is recommended to go through these tutorial as well.