optional parameters widget flutter code example
Example 1: dart optional positional parameters
void myFunction(String name1, String name2, [String name3]) {
}
void myFunction(int x, {int y = 2}) {
}
myFunction(2, y: 4);
Example 2: dart optional parameters
Curly brackets {} are used to specify optional, named parameters in Dart.
readFile(String name, {String mode, String charset = 'utf-8'}) {
}
Named parameters are referenced by name,
which means that they can be used during the function
invocation in an order different from the function declaration.
readFile('hello.dart');
readFile('hello.dart', mode: 'w+');
readFile('hello.dart', charset: 'iso8859-1');
readFile('hello.dart', charset: 'iso8859-1', mode: 'w+');
readFile('hello.dart', mode: 'w+', charset: 'iso8859-1');