Introduction to Dart Programming

Introduction to Dart Programming

Dart is a programming language developed by google to create cross platform apps, dart like any other programming languages needs SDK which all the tools needed to develop applications using Dart. Click the ling to the official Dart website to install the latest Dart Sdk. Dart is a statically typed programming language, in dart you need to specify the the data type of a variable while creating it. But also Dart can automatically detect the type of variable data type.

Variables in Dart

A variable that is not initialized is by default assigned with null value, there are a couple of primitive data types in dart like

int,boolean,String && double

You can ignore the datatype initialization while creating your variables by using

var

Where dart will automatically infer the data type of the variable based on the assigned value. The created variable cannot be assigned a value of different data type during run time.

dynamic

A dart data type which is capable of holding any data type unlike the var data type. While creating dart variables there are keywords used like

final, const

Where const means compile time constant where a value must be assigned to that variable while compiling the program. While final is a run time constant where a constant value can be assigned during program execution.

Functions in Dart

A function is a reusable and organized bloc of code performing a single task. A function must have a return type. A function can have positional or named parameters where they can be assigned default values or left blank.

Example of a function:

var addNumbers(a,b){
return a+b;
}

Lists in Dart

A list is a collection of data having the same datatype, in other languages Lists are called Arrays. Data in lists are ordered and can be sorted, every element in the list is indexed and can be accessed by the index number uniquely starting from 0. There are two types of lists

  1. Fixed Length List

    List<data type> list_name = List(length);
    

    An integer value is assigned as length of the list, defining the number of elements a list can hold.

  2. Growable List

    List<data type> list_name = List();
    

    A growable list doesn't have a limit means it can hold any number of elements.