As I kick off my #30DaysOfFlutter journey, the first step is to get familiar with Dart, the powerful language behind Flutter. Today, I'll be diving into the syntax and structure of Dart, and what better way to start than with a classic "Hello World" program?
Dart is a modern language with a clean, concise syntax. Here's a quick overview:
- Variables: Dart is statically typed, meaning you must declare the type of a variable. However, Dart can infer types, making code cleaner.
- Functions: Functions are first-class objects in Dart. You can pass them as parameters, return them from other functions, and assign them to variables.
- Classes: Dart is object-oriented and supports classes, interfaces, and mixins.
- Libraries: Dart uses packages and libraries to organize code and share functionality.
you can use online compiler for this too : https://www.tutorialspoint.com/execute_dart_online.php
Here's how to write a simple "Hello World" program in Dart:
void main() {
print('Hello, World!');
}
Breakdown of the Code main() function:
Every Dart application starts with the main function. It's the entry point of the application. Syntax: void main() { } print() function:
The print function is used to output text to the console. Syntax: print('text'); In this example, the main function calls print, passing the string 'Hello, World!'. When you run this program, you'll see Hello, World! printed in the console.