Booleans in Dart

Bryan Cairns
A free video tutorial from Bryan Cairns
Computer Guru
4.4 instructor rating • 13 courses • 80,505 students

Learn more from the full course

Dart - Beginners Course

No experience required

01:59:49 of on-demand video • Updated February 2019

  • Installing an IDE
  • Varibales
  • Arrays
  • Flow Control
  • Functions
  • Error Handling
English [Auto] It is an object oriented language. What does that mean exactly. It means that it's filled with objects. So what is an object. An object is simply something that exists. It gets a little deeper than that but just think of that construct in your mind create a new project called a dart console application hit next to give us a name of balls and hit finish. Once the idea is opened up we're going to delete some of stuff that we just don't need. We know that this is the main entry point and we're going to create what's called a variable. When I say bull is on so this is a variable. It's just simply something that's going to change all the time variables a scientific term the opposite of a variable is a constant something that will not change. We're talking about something that will change so let's change this. There are different data types. Bool is a data type. Stands for boli which simply means true or false. So the structure creating a variable is you need to give it a data type. In this case simple along with the name. You can also give it a value. For example is dog equal false. So we get an initial value. Let's test these out. Notice how when I say is it automatically does code completion. This is why you use an ID. It saves you a little bit of guesswork and typing. We're going to print the is on variable and see what it says. Says null. What does it all mean. No it means it doesn't exist. It's not actually an object yet it's not entirely true. There's a difference between an object and an instance of an object everything and art is an object bake that into memory everything is an object an instance of an object is different. That means that the object actually exists and is running in memory. No means the object is simply not there. For example if we switch to is dog so it's it false as that. And we can switch this to true just for illustration. Very simple. So to get rid of is dong and let's play around with this a little bit here. Notice the structure of this print function we're saying is on equals dollar sign. And then these little brackets with is on. What we're really doing here is this is a variable in itself called a string which will cover in the future. Tauriel this is not actually assigning a value. This is just part of the string this dollar sign brackets. This says we're going to run some code. And here's the code we're running. In this case we're just simply handing it the value of that variable. And we're going to change it around a little bit. I'm going to cut that paste it up here. And let's run this and see what happens. You can see how it says no true or false. So this is a good demonstration of what a variable is something that's going to change. It starts with absolutely zero assignment and then we're changing it to true or changing it defaults. We could have very easily started with true or false and it would have voided no. Now when I say everything is an object and I mean everything. For example we can say is on dot and you notice how we have some functions here to string hash code runtime type and no such method of occasion what we're going to do is we're going to say print design is a runtime type and we want to just see what this says and says it and then is able. That's called a runtime type. The difference between a runtime type and just a variable is very simple. Dart has something called a where we could have very easily said VRR is that a ball there just means it's a generic object d'art is smart enough to know what it is when we run this you'll see there's no change it still knows that it's a Bulleen even though we're declaring it as a vr.