Your First Dart Application
Explore how to write your first Dart application by understanding the main() function, which acts as the starting point of any Dart program. Learn the basic syntax and how to output text, laying the foundation for further Dart programming.
We'll cover the following...
The main entry point
Every application has some point in its program that serves as the entry point to the application. When an application runs, it starts from that specified entry point. In Dart, the entry point is the main() function. You might be unfamiliar with what a function is at this point; that’s okay. For now, just remember that when you run a Dart program, the compiler looks for the main() function and executes the code written in that function. If main() is not found, you will get an error and your application won’t run. The code you write in main() is encapsulated in curly brackets ({}). Let’s look at the general syntax below.
The keyword main is followed by a set of parentheses (()) which is followed by an opening curly bracket ({). Start writing your code from the next line and when you’re done, insert a closing curly bracket (}) in the line after the last line of your code.
Insert Code Hereis where you write the code for the functionality you want your application to perform.
Hello world
Let’s look at the famous “Hello World” program, which is usually the first application you learn to code when learning a new programming language. The purpose of the application is to simply print “Hello World”.