3.2. Dart Basics: Variables and Data Types

Página 20

Dart is a programming language developed by Google that is used to create high-quality mobile, web, and desktop applications. It is the core language used in Flutter development. In this article, we'll focus on the basics of Dart, specifically on variables and data types.

Variables in Dart

In Dart, a variable is a name given to a location in memory where you can store values. You can declare a variable using the 'var' keyword, followed by the variable name. For example, 'var name;'. Here, 'name' is a variable that can store any type of value.

Dart is a strongly typed programming language, which means that when you declare a variable, the variable's data type is checked at compile time. However, Dart also gives you the option of declaring variables whose type is only known at runtime. This is done using the 'dynamic' keyword. For example, 'dynamic value;'. Here, 'value' is a variable whose type will only be known at runtime.

Data Types in Dart

Dart supports the following data types:

Numbers

There are two types of numbers in Dart: integers (int) and floating point numbers (double). Integers are numbers without a decimal part. Floating point numbers are numbers with a decimal part.

Strings

A string is a sequence of characters. In Dart, strings are represented by double or single quotes. For example, 'Hello, World!' or "Hello, World!" are valid strings.

Booleans

A boolean is a data type that can have only one of two possible values: true or false. In Dart, Booleans are represented by the keywords 'true' and 'false'.

Lists

A list is an ordered collection of items. In Dart, lists are similar to arrays in other programming languages. You can declare a list using square brackets. For example, 'var list = [1, 2, 3];' declares a list of integers.

Maps

A map is a collection of key-value pairs. In Dart, you can declare a map using curly braces. For example, 'var map={'name': 'John', 'age': 30};' declares a map with string keys and values ​​of any type.

Conclusion

The basics of Dart, including variables and data types, are fundamental to developing apps using Flutter. Understanding these concepts will allow you to build more complex and efficient applications. Although Dart is a strongly typed programming language, it also offers flexibility with declaring dynamically typed variables. Additionally, Dart supports multiple data types, including numbers, strings, Booleans, lists, and maps, making it a robust and versatile programming language.

Now answer the exercise about the content:

What is the role of the 'dynamic' keyword in the Dart programming language?

You are right! Congratulations, now go to the next page

You missed! Try again.

Next page of the Free Ebook:

213.3. Dart Basics: Conditional Structures

Earn your Certificate for this Course for Free! by downloading the Cursa app and reading the ebook there. Available on Google Play or App Store!

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text