Flutter: Data types
Dart supports several data types. In this article, we will learn about some of them:
Name | Examples |
---|---|
String | "Hello world" |
int | 1, 5, 10, 100 |
double | 1.5, 0.25, 10.5 |
num | 1, 1.5, 10 |
bool | true, false |
String
The String
data type holds a sequence of characters. You can create a string using single quotes '
or double quotes "
.
var myString1 = 'This is a string';
var myString2 = "This is another string";
int
The int
data type holds integer values no larger than 64 bits, depending on the platform. On native platforms, values can be from -263 to 263 - 1. On the web, integer values are represented as JavaScript numbers (64-bit floating-point values with no fractional part) and can be from -253 to 253 - 1.
var myNumber = 5000;
double
The double
data type holds floating-point numbers.
var myDouble = 1.25;
num
The num
data type can hold integers or floating-point numbers. For example:
num myNum1 = 100;
num myNum2 = 1.25;
bool
The bool
data type can hold only two values: true
or false
:
var myBoolean = true;
DartPad example
Conclusion
We learned about some of the data types supported by Dart. Of course, there are many more data types like Maps, Lists, Sets, etc. But we will learn about them in the following articles of this course.