In this tutorial, we continue with an explanation of the Hello World Example from Part 1.
Open a DartPad and input the following code:
1 import 'dart:core';2 void main(){3 print('Hello World');}
- This is an
import
statement to bring Dart’s core library into our app. Thedart:core
library provides core functionality that every Dart app needs, such as theprint()
function from line3.
Thedart:core
library is automatically imported by Dart, so it is not strictly necessary. - All Dart apps begin life inside the
main()
function.main()
is a required, top-level function where execution starts. Ourmain()
function returnsvoid
which means it returns nothing to whatever code calledmain()
. - This is a
print()
function that is part of thedart:core
library we imported in step1.
We pass the string'Hello World'
as an argument to theprint()
function. Theprint()
function then handles outputting Hello World to the DartPad’s console section.
Help me help others by clicking on that clap button and leave a response.
In summary, a basic Dart app is just implicit/explicit import
statements and a required main()
function. Whilst this is not a very interesting app, it is all that is required. In Part 3, our apps will start to get exciting as we learn to store data using variables. Variables and data are fundamental to the success of your app and sound knowledge in this area will strengthen your programming skills. Happy coding…