Dart For Flutter Beginner (Part-1)

Onexlab
Onexlab
Published in
3 min readDec 8, 2019

Contents

Part 1: Introduction To Dart

  1. What is Dart
  2. Dart’s Hello World!
  3. Comments
  4. Operators
  5. Control Flow

Part 2: Dart Data Types

  1. Basic Data Types
  2. Complex Data Types
  3. Dynamic Data Type
  4. Final & Const

Part 3: Dart Functions

  1. Basic Functions
  2. Types of functions
  3. Scope

Part 4: Dart Object-Oriented Programming

  1. Classes
  2. Constructors
  3. Inheritance
  4. Enums

Part 1: Introduction To Dart

1. What Is Dart

Dart is a client-optimized programming language for fast apps on multiple platforms. It is developed by Google and is used to build mobile, desktop, backend and web applications. Dart is an object-oriented, class defined, garbage-collected language using a C-style syntax that transcompiles optionally into JavaScript.

Why Does Flutter Use Dart?

Dart supports Just In Time (JIT) as well Ahead Of Time (AOT) compiling.

Just In Time (JIT)

Just In Time (JIT) allows fast development called Hot-Reloading that use in the Flutter App Development.

Ahead Of Time (AOT)

Ahead Of Time (AOT) compiler converts Dart into an efficient native code which makes flutter faster.

2. Dart’s Hello World

We are going to write a very simple program that prints “Hello World!” using Repl Editor as below. Dart uses .dart extension to write Dart code. You can see there is a file `main.dart`. If you hit the play button top center of the embedded editor. It will compile the dart file and print “Hello World!”. You can practice writing something else with the following editor. Void main is an entry point of the Dart file. “print” is used to print output “Hello World!”.

3. Comments

Dart support 3 types of comments

Block comment

/*
The code below will
print Hello World!
*/
void main() {
print("Hello World!");
}

Inline comment

void main() {
// String name;
print("Hello World!");
}

Documentation comment

class Box {
/// The value this wraps.
var _value;
/// True if this box contains a value.
bool get hasValue => _value != null;
}

5. Control Flow

Control flow in the Dart is similar to other high-level programming languages.

if-else:

In the following program, we have bool variable “printString” set it to true and checking that variable in the if condition that if printString is true then it will print “printString is true” else it will print “printString is false”

Switch:

In the following program, we have “fruitJuice” variable that assigned String “C” and that variable we are passing to the switch which will print “Carrot” if we have a break statement in the switch.

Switch with continue

In the following program, we have variable “fruitJuice” that assigned String “ABC” we are using “Continue” statement instead of break. Which will print

“Apple”

“Beatroot”

“Carrot”

Instead of single String

Ternary operator:

The “Ternary” operator is a kind of if/else substitute. In the following program, we are assigning value to variable “message” with the help of “Ternary” operator “?” (like if) and “:” ( like else). If “printString” is true it will print “Hello World” else “Welcome”. Try to run following program

LINK TO PART — 2 (Coming Soon)

--

--