akifislam / Basics-of-Dart-Programming

This repository contains some code snippets that might be helpful for a new Dart developer. It is a mixed of C++, Java, Javascript and Python syntax.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction to the Dart

Hello World

Every app has a main() function. To display text on the console, you can use the top-level print() function:

void main() {
  print('Hello, World!');
} 

Variables

Even in type-safe Dart code, most variables don’t need explicit types, thanks to type inference:

var name = 'Voyager I';
var year = 1977;
var antennaDiameter = 3.7;
var flybyObjects = ['Jupiter', 'Saturn', 'Uranus', 'Neptune'];
var image = {
  'tags': ['saturn'],
  'url': '//path/to/saturn.jpg'
};

Control flow statements

Dart supports the usual control flow statements:

if (year >= 2001) {
  print('21st century');
} else if (year >= 1901) {
  print('20th century');
}
for (final object in flybyObjects) {
  print(object);
}
for (int month = 1; month <= 12; month++) {
  print(month);
}
while (year < 2016) {
  year += 1;
}

Functions

Dart recommends specifying the types of each function’s arguments and return value:

int fibonacci(int n) {
  if (n == 0 || n == 1) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}
var result = fibonacci(20);

A shorthand => (arrow) syntax is handy for functions that contain a single statement. This syntax is especially useful when passing anonymous functions as arguments:

Read more from here

About

This repository contains some code snippets that might be helpful for a new Dart developer. It is a mixed of C++, Java, Javascript and Python syntax.


Languages

Language:Dart 100.0%