main_ has_ too_ many_ required_ positional_ parameters
The function 'main' can't have more than two required positional parameters.
Description
#
The analyzer produces this diagnostic when a function named
main
has more
than two required positional parameters.
Example
#
The following code produces this diagnostic because the function
main
has
three required positional parameters:
void main(List<String> args, int x, int y) {}
Common fixes
#If the function is an entry point and the extra parameters aren't used, then remove them:
void main(List<String> args, int x) {}
If the function is an entry point, but the extra parameters used are for when the function isn't being used as an entry point, then make the extra parameters optional:
void main(List<String> args, int x, [int y = 0]) {}
If the function isn't an entry point, then change the name of the function:
void f(List<String> args, int x, int y) {}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.