From the course: Flutter Essential Training: Build for Multiple Platforms
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Difference between var and dynamic - Flutter Tutorial
From the course: Flutter Essential Training: Build for Multiple Platforms
Difference between var and dynamic
- [Instructor] We have learned that when we define variables it is important to define the data type along with it as well. In other words, we explicitly declare the type that would be inferred. However, what if we do not know the type beforehand? That's when var or dynamic comes handy. In this case, we have redefined the data type as double but what if we want to keep things open? We can make this as either var or dynamic. So let's elaborate on this example. When we assign a value to a dynamic declaration of a variable the compiler assigns the data type, depending on the value assigned. In this case, it is a double value. So the compiler will assign double to price. You can verify this with this runtimeType property. See, this is a double. Now, if the same variable is reassigned a string value then what happens? So in this case, price becomes rupees 40.5. This is a string value. Now if you print(price.runtimeType)…
Contents
-
-
-
Entry point to a Dart application1m 59s
-
(Locked)
Overview of data types: Numbers and strings5m 41s
-
(Locked)
Overview of data types: Bool, lists, and maps8m 11s
-
(Locked)
Difference between var and dynamic3m 2s
-
(Locked)
Functions in Dart7m 43s
-
(Locked)
Overview of classes and objects: Part 15m 13s
-
(Locked)
Overview of classes and objects: Part 28m 30s
-
-
-
-
-
-
-
-