The general-purpose programming language Dart is available for free. Google was the one who developed it initially. The object-oriented language Dart has syntax in the C manner. Unlike other programming languages, it offers concepts like classes and interfaces. Arrays are not supported by Dart. Arrays, generics, and optional type are examples of data structures that can be replicated using dart collections.
The following code shows a simple Dart program ā
Variables and Data types
The storage location variable is called a data type, and data types are just the different kinds and sizes of data that are related to variables and functions.
The variable is declared in Dart using the var keyword. Below is a definition of the var syntax.
The final and const keyword are used to declare constants. They are defined as below ā
Dart language supports the following data types ā
- Numbers ā It is used to represent numeric literals ā Integer and Double.
- Strings ā It represents a sequence of characters. String values are specified in either single or double quotes.
- Booleans ā Dart uses the bool keyword to represent Boolean values ā true and false.
- Lists and Maps ā It is used to represent a collection of objects. A simple List can be defined as below ā.
The above list generates the [1,2,3,4,5] list.
A map can be described as follows:
Dynamic ā If the variable type is not defined, then its default type is dynamic. The following example illustrates the dynamic type variable ā
Decision Making and Loops
A decision-making block assesses a situation prior to carrying out the instructions. If, If..else, and switch statements are supported in Dart.
A block of code can be repeated using loops until a predetermined condition is satisfied. The for, for..in, while, and do..while loops are supported by Dart.
Let’s see a basic example of how to use loops and control statements.
The above code prints the even numbers from 1 to 10.
Functions
A function is a collection of statements that work together to accomplish a particular goal. Let us examine a basic Dart function as demonstrated here .
The above function adds two values and produces 7 as the output.
Object Oriented Programming
The language Dart is object-oriented. Features of object-oriented programming, such as classes and interfaces, are supported.
A class is an object creation blueprint. The following are included in a class definition:
- Fields
- Getters and setters
- Constructors
- Functions
Now, let us create a simple class using the above definitions ā