Sitemap
Arte Bi

Arte Bi

Dart: Variables and basic types

2 min readAug 17, 2023

This article is part of a series on How to start creating mobile applications for Android or iOS using Dart & Flutter.

Press enter or click to view image in full size
Photo by Markus Spiske on Unsplash

Variables in the Dart language are named memory areas used for storing data. They allow us to store, modify, and retrieve values of various data types, such as numbers, strings, boolean values, and much more. Variables enable us to work with data and pass it between different parts of a program.

int age = 25;

In this example, we have created a variable named “age” and assigned it a value of 25. The variable type is specified as “int,” which stands for an integer.

String name = 'John';

Here, we have created a variable named “name” and assigned it a value of “John”. The variable type is specified as “String,” which signifies a text string.

bool isStudent = true;

In this case, the variable “isStudent” has a value of true, indicating that the person is a student. The variable type is bool, which is a boolean data type.

double salary = 1500.50;

This variable “salary” contains a floating-point value.

Get Arte Bi’s stories in your inbox

Join Medium for free to get updates from this writer.

In addition to declaring variables with explicit data types (as in the examples above), Dart also allows the use of the “var” type, which enables the compiler to automatically determine the variable’s type based on the assigned value. For example:

var temperature = 25.5;

In this case, the variable type of “temperature” will be automatically determined as double.

By using the variable name, we can access the data it refers to. Example:

void main() {  
int age = 25;
String name = 'John';
bool isStudent = true;
double salary = 1500.50;
var temperature = 25.5;

print(age);
print(name);
print(isStudent);
print(salary);
print(temperature);
}

In this example, we use variable names (passing them as parameters to the “print” function) to display their values on the console.

--

--