What is the main() function in Dart?

The main() function is a top-level function in Dart that initiates the execution of the program. It is the Dart programming language’s most important and crucial feature. In a program, the main() function can only be used once.

The main() function is responsible for all kinds of execution, including user-defined statements, functions, and libraries. The program starts with the main() function, which contains variable declarations, functions, and user-defined executable statements.

Syntax

void main()
{
    //main() function body 
}

Parameters

An optional List <String> parameters may be used as function arguments. These parameters can be used if we need to influence our application from the outside.

Return

The main() function returns void.

Code

The code below shows a basic example of the use of main() function in Dart.

main(){
print("Welcome! This is a shot on main() function in Dart");
}

The code below shows how to pass arguments inside the main() function.

main(List<String> params){
var params =["a","p","e"];
//print the length
print(params.length);
//print the list
print(params);
}

Free Resources