The main() function

Every app must have a top-level main() function, which serves as theentrypoint to the app. The main() function returns void and has anoptional List<String> parameter for arguments.

Here’s an example of the main() function for a web app:

1. void main() {
2. querySelector('#sample_text_id')
3. ..text = 'Click me!'
4. ..onClick.listen(reverseText);
5. }

Note: The .. syntax in the preceding code is called a cascade. With cascades, you can perform multiple operations on the members of a single object.

Here’s an example of the main() function for a command-line app thattakes arguments:

1. // Run the app like this: dart args.dart 1 test
2. void main(List<String> arguments) {
3. print(arguments);

5. assert(arguments.length == 2);
6. assert(int.parse(arguments[0]) == 1);
7. assert(arguments[1] == 'test');
8. }

You can use the args library todefine and parse command-line arguments.