2. Dart Program Structure

Marc Kirk
2 min readMar 22, 2020

--

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');}
  1. This is an import statement to bring Dart’s core library into our app. The dart:core library provides core functionality that every Dart app needs, such as the print() function from line 3. The dart:core library is automatically imported by Dart, so it is not strictly necessary.
  2. All Dart apps begin life inside the main() function. main() is a required, top-level function where execution starts. Our main() function returns void which means it returns nothing to whatever code called main().
  3. This is a print() function that is part of the dart:core library we imported in step 1. We pass the string 'Hello World' as an argument to the print() function. The print() 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…

--

--