 Hey everybody, this is Brian. Welcome to the second Flutter tutorial. I know it says Dart here, but before we really dive into Flutter, if you remember from our previous video, we actually have to learn the Dart language first. Don't worry, it's pretty painless, so we're going to just click on language. We're going to go to tour, and this is what I'll really be working from, although I won't be following it verbatim, but I want to definitely point you to where you can find additional information here. So tour of the Dart language, they walk you through what is a basic program, and we're just going to actually open IntelliJ, create a new project. We're going to make a new Dart console application, and let's call this a varetest, just because I'm horrible at naming projects. And this will take just a second to load. I actually don't know why this is so slow. I have just an ungodly amount of RAM and two solid state drives. This is actually my PC I use for video gaming, so I'm not sure why this takes a while. But while that's sitting there churning in the background, what we're going to really cover in this tutorial is what is a variable, what is a constant, what is a final? There's a distinction there, and it's a little tricky. And then some of the built-in types, you can actually click on that built-in types, and you'll see there's numbers, strings, bolines, lists, maps, runes, and symbols. Not going to really cover these last two, but you can definitely look them up in the official Dart documentation. All right, so now that we have got our brand new Shiny program, let's just run this and make sure everything builds correctly. If you followed along and you've got the same setup as I do, you'll see Hello World 42. That's actually kind of funny. It's funny because of a book by Douglas Adams called Hitchhiker's Guide to the Galaxy, where the ultimate answer to everything was 42. So we're going to remove that import statement and remove the print statement. Just save and run it again, and you should have absolutely nothing there. That'll be a good starting point for us. Now, structure of a Dart program, you can see how the main.dart file is in the bin, and this is our main statement or our main function. This is the entry point to the application. So we're just going to say print Hello World. What we're doing here is we're calling a function. You've probably seen this in other videos, and if we just save and run, you'll see, sure enough, it says Hello World. But what's really going on here under the hood? We have a function which we're going to cover in a future tutorial that works with something called a variable, which is right here. Hello World is actually a string variable. So what is a variable? A variable is simply something that will change over time. So variable is actually scientific term, something that will change over time. So we're just going to say var something. Whoops, if I could spell Hello World. So what's really going on under the hood is Dart is creating a new variable with that information in it. So this and this are exactly the same thing. You can save, run, and it does literally the same thing. To kind of drive that point home, you can actually press dot after Hello World, and you see it brings up all of the other functions in the string class, which if all of that sounds like voodoo nonsense, don't worry, we're going to cover all this in future tutorials, but you just need to understand that a variable is something that will change. To drive that point home, you can say, oops, hope if I spelled something right, cat's rule. Now if you're dog lover, you can put dog's rule, I won't come find you, but the point is we've changed this. We've made changes to it. Now on the flip side of that, a constant is a scientific term that means it is constant. It will never change. So we'll say const, what do we want to put here? We'll just say nope equal one. So if we try to take our nope variable here, and I should say nope constant and make this a two, notice how there's got that little red underline and it starts complaining. And if we even try to run it, it's going to crash. And it's going to say, cannot assign to final variable, nope. Now what's going on here? We call this a const, but it says final variable. So there's a little bit of information you need to know. And I found this really great article. I'm just going to put this right in the code. But the difference between final and const is it's tricky to understand and you won't really get it until you really get into the language. But I wanted, you know, right up front to tell you there is a difference. If you're writing your code and you're following along say in another book and you say final, nope one, nope equal two, essentially you're doing the same thing, quote unquote, you have something that you cannot change. And it's going to complain every time. And if you try to run it, let's comment that out, you'll see that. Yes, it still crashes. Cannot assign to final variable, nope. Okay, let's comment that out. By the way, if you don't know what a comment is, a comment is just something that the computer completely ignores. It's there for your enjoyment, if you will. A lot of times programmers will comment code as they go. So you can understand it not just from a machine perspective, but from a very readable human perspective. So anyways, back to this variable, if something will change, constant and final cannot be changed. So what's the difference between constant final? This article sums it up the best. Ignore static for now. But final means a single assignment. A final variable or field must have an initializer. What does that mean? Basically, it means that you have to give it a value. So for example, if we just comment that out, you can see how it must be initialized, you must actually give it an initial value. Let's try the same thing with nope here. Notice how nope is also complaining, must be initialized. So you understand what an initializer is, and because it's a constant or a final, it has to have a value starting up. Once assigned a value, a final variable's value cannot be changed. Final modifies variables. Basically, it takes the variable and sets it in stone and says, this will never change. For example, a constant would be the sun. Unless it explodes, it is a constant. It will never change. Or I should say it's a final. It'll never change. A constant, however, has meaning that's a bit more complex and subtle in dark. Cons modifies values. Notice the distinction here, values. Final modifies the variable where constant modifies the value. When you look at these two real quick here, this is the variable, this is the value. So let's go back here. A final modifies the variable. So final modifies this, the variable, where constant modifies the value. So you can pass that constant around to other constants. It will always remain a constant, but you can pass it around with a different variable name, whereas a final is final. That is the only time that can ever exist in that. So if we try to do a constant no-per, see how we're getting an argument. No-per is already defined. You're going to get that anyways. But that's really the distinction. And it gets really deep. And like I said, you're not going to truly understand it until you get really good with dark. And you end up in those cases where you need to understand the difference between the two. But I'm going to take this particle and throw it in here, just so we kind of have that as a reference. What is this? Cancel. All right. So which one should you use? I use const just because it suits my needs. And until I get into complex applications, I won't really need to know the difference. Now, if that's not confusing enough, there is that other one called static, which we'll get into in future tutorials, which really deals with classes. And that's why we're going to cover in future tutorials. So, onward. Now that your brain is completely numb, just to understand there is a variable, if something will change, and a constant or a final will not change. It's changeable versus not changeable. In this tutorial, we're going to be working with things that change or variables. There's different variable types. Notice how in the front I put there or const or final, that's the type. Well, there's a lot more types here. So we're going to get into numbers. And they are, well, numbers. Yeah, exactly what you think they are. So we'll say numb. And we'll say age equal 12. Why not? Now, if we type AGE and hit the period, you see that we go into that class of scope, and we get a whole lot of functions. This is a lot of built in functionality. In Dart, everything is an object, much like in Java or other languages. So because everything is an object, you can actually go in and get reusable code something somebody else has already written, like we can round, we can double, we can convert floor, ceiling, ABS to string, is it not a number, etc, etc. Now notice here on the right, you see some words like int, double string, what are these? Well, that's the return type. So that function is going to return a double where this function will return an integer. So you know automatically what you're going to get. So as you would expect, because this is a variable, let's add 20 years to this. It looks like 30 years to this. Why not? We're going to just print the age out here. So you can see how now it is 42. And I'm kind of doing this on the fly here. So you see how it says age is 42. If you put the dollar sign inside, you can actually reference a variable outside. If that makes no sense, let me repeat it. What we've done here is we've created a string variable. But inside that string variable, we're referencing an external variable called age. See how that works. Otherwise, what you would need to do is actually go whoops, plus age. Now notice how the argument type num cannot be assigned to the parameters type string, because this right here is actually a string. If you hit the period or the scope operator, you will see that you have options or functions from that class that you can choose from. So we actually got two variables we're working with here, this variable and this variable. So it's kind of matter of preference. Some people like doing this. Some people like doing that. Do what's comfortable to you is really what you should do. And just in case you were curious, if you're going to do it like this, you just say age dot two string, and it converts it to a string for you automatically. So you can actually let's do like this. And we'll run it just so you can see age is 42. I'm going to put it back the other way, just for the purpose of this tutorial, though. So I actually got a little ahead of myself here. So a boolean, we're going to actually jump backwards in time here. And we're going to say boolean is working equal false. A boolean is like a light switch. It's either on or off, true or false. And we're going to say is working equal true. Booleans are very helpful for certain things like, for example, let's go back to our age example here. If we want to say is infinite, is age infinite, it's going to return a boolean value. And it's going to tell us whether or not that number is infinite or negative or finite. All right, let me check. Somebody messaged me. That's the problem with doing videos real time. I don't edit my videos. So you'll see a lot of seeing here, a lot of craziness going on here. One thing we should really be aware of is that there is more than one type of number. For example, an int would be let's say cats, the number of cats I have actually don't have any cats right now. So I'm lying a little bit. And then there's a double. And let's say pi equal 3.14. So what's the difference between an int and a cat? And these are big, big, big, big numbers. You can actually go out to the Dart documentation and you'll see integer values generally be between negative two to the 53rd power to two to the 53rd power. That is a huge number where a double is a 64 bit double precision floating point numbers as specified by the IEEE 754 standard. That's a mouthful. Basically what you need to understand is almost all numbers that you create are going to be converted either into an integer or a double depending on what they are. But both integer and double actually inherit from the number class. What does that mean exactly? Well, what it means is that if you say age dot, you'll see all these things like round to double to end to floor, blah, blah, blah, blah, blah. What inheritance does is if we say cat dot, you'll see that it's inheriting all of those plus it adds a few little extra. So an inheritance is think of back to scientific terminology, you inherit your genes from your mother and your father. Everybody does unless you were born in the laboratory. But anyways, we won't get into that. So you have parts of both your mother and your father. So for example, an integer has parts of num, a double has parts of num. Pretty simple. We'll cover that more when we get into our classes tutorial, but just understand that there's essentially two different types of numbers. There's integers and doubles, and you can use the generic num if you don't know what type of number it actually is. See, it won't break anything if we do that. But if we try doing that with an integer, it gets a little angry at you. It says it has to be a double. All right, now we get into the really fun stuff strings. I don't know if you guys can hear that. It's actually it's I'm in Michigan, and it's just starting to get cold and snow and my neighbor is now just trying to get their leaves up and I can hear them like yelling at each other. It's kind of funny. So so we'll say string title equal. Hello world. So what is a string? A string is a sequence of characters. What is a character? A character would be these individual letters. Now you should note that I think there's 200. We're on the internet. So somebody will correct me if I'm wrong. 255 different characters, not all of them are actually human readable. For example, the space is a character, a tabs a character, zero, not the numbers there, but just nothing is a character. Things like that. So a string is a sequence of characters. Now if you want to work with unicode, spoiler alert, you'll need to work with something called a rune, which we're not going to cover specifically in this tutorial. We may cover it in future tutorials if there's like a huge public outcry for it. All right. So you get now that it's a sequence of characters. What can you really do with this? I mean, what does a string really let you do? Strings let you do a whole lot of really, really cool stuff. For example, you can say title equal. Oops, my kittens. Just why not? I had no idea where I was going with that. And we're just going to say print title. So you can actually build strings. There is a class out there you should use called a string builder. If you're going to actually start building strings, it's much more efficient than working with a string directly. But for this tutorial, we're going to just cover strings. All right. So back to this. What do we want to do? Let's say we want to play around with this thing. Let's actually... So we're just going to have this say hello world. Right here. Let's say we want to know some values out of this thing. Let's say we want the... We want to extract part of that string. Substring. So we want to start index. Let's say we're going to start at zero and we want the first four out of this thing. Let's run this and you'll see that nothing happens. Because we're not actually changing this variable. We're actually calling a function that's returning a variable. So let's grab this and you'll see the first four is... Whoa. That's kind of dark. I didn't mean to do that. The first four is hell. Sorry, ladies and gentlemen. But what we're doing here is we're grabbing a substring or the first four characters. Now, you can see how the four characters are outlined there. What is this zero? Well, under the surface, this is really a list of characters. We're going to cover lists here in a few minutes. But lists are zero based indexes, meaning it starts with a zero instead of a one. So this position right here before that H is zero. Zero, one, two, three, four. That's how you get those four characters. So substring starts with zero and then we tell it how many characters we want or you could start at a different one. So for example, let's say we start at one and now we're going to get some gibberish eel with a space. That's not a good example. Let's do two. That's really not a good example either. Let's grab five characters. Why not? Hello. So you can see... Oh, you know what? We should cover other things as well. Let's put this back the way it was, just so I can really freak people out when they download this code. And let's say we want to... I'm really doing this video on the fly here. So bear with me here. We want to replace all. So we're going to say title equal title that replace all. And we want to get rid of the L's, the uppercase L's anyways, and replace those with Z's. As you can see, we've got these two Z's in there now. Pretty neat. Now, one thing you can really do with a string that's kind of interesting is you can play around with it. So we're going to say string, book my world's issues in a day. What have we done here? You notice how instead of using single quotes, we're using double quotes. You can use those interchangeably. It doesn't really matter. And you would use those for specific instances like this where you want to put a single quote in there. This could also be written as let's say string, book two. Notice how it's got that slash in front of the single quote. That's called an escape sequence. You would use that for specific things like, for example, this is a single quote. So anything after the escape is the sequence we're going to inject into the string. For example, let's say we want to do a slash n, which is a new line terminator. So let's print these two out. I'm going to print book. And then we're going to print out book two, just so you can see the difference here of what we've done. And you can see how my world's issues in a day and then my world's issues hard to turn are actually new line in a day. Now on some platforms, like Windows, I think it's Rn instead of just n. So it gets into some platform specific stuff there. But you can see that really it doesn't matter whether you single or double quotes, and it's kind of personal style and preference on which one you use. All right, so now let's get a little different here. And let's say string names equal, just going to make some names there. And we're going to assert something. Now assert is a special function in Dart that will say this must return true, whatever we put in here has to return true. So let's say names dot, oops, contains. And we're looking for Heather. I hope if I put that at the end there. Notice how each line has to end with a semicolon. That tells us that we are at the end of the line. Very funny, huh? So when we run this, nothing happens, but we've done this assertion. So let's say just random junk in here and we try to run this now. Notice how it'll air out. Names contains whatever is not true. So that'd be a good way of testing your variables. Let me put this here. So we're going to talk about lists next. Lists are a list of objects. So let's say list. And you notice how the IntelliSense pops up and it says there's this weird bracket with an E in there. What was that? Well, this is called generic programming. And what it allows us to do is reuse code. And we're going to get into this in future tutorials just right now understand that we have to give it a value type, or I should say a variable type, sorry. In this case, string. So we're going to say list equal names dot split. Split's going to take a pattern. And we're going to split that based on the comma. So what are we really doing here? If we examine name dot splits, I'm sorry, names dot split, you can see how it's returning a list with string. So a list is going to be a list of objects. In this case, we want a list of strings we were could easily have said integers or doubles or even, you know, there if we don't know what type it is. Actually, I don't think it would allow us to do that. But in this case, we're just going to use a string. So think of a list like a, what's a good example here? Think of a list like a shopping cart. Shopping cart, you just throw anything you want in there. But we're saying a specific type of thing. So in our shopping cart, you can only put strings. We don't want to put integers or doubles or anything else. We only want strings in there because we're going to want string shopping. If there is such a thing. So from our list, we can then pull items back out. Or we can just examine the list. So let's say we want to know what's in our list. Save this and run it. In our list, we have Brian Heather, Chris Carl. Let's say we want to get the item at or I'm sorry, the element at the second index. Because remember a list we talked about this is zero base. So the second one, zero, one, two, is Chris. Now you can also shorthand this as most people do and say list bracket two. That way you don't have to do the element at does the exact same thing under the hood. You see how we got Chris there twice now. Now from here, let's say we want to add to our cart. We want to add a string here. So we're going to add Bob. Bob's been a good boy. He can go into our little shopping cart of strings. And let's print our list out again. And you see we now have Bob at the very end. Now let's say we want to add somebody, but we want to add them in the list, not at the very end. So we're going to actually say insert. And notice how it's wanting an index and a string element. So insert, we're going to insert this at the first position. And we're going to call this. I need a name. I need a good name. Back to our hitchhiker's guide to the galaxy. Let's just say we're going to add forward. I should have added Slardie Bart fast, but yeah, let's actually do that. He's a character in the book. I love that book. It's funny. So we're going to print our list out and you'll see how in the first position, because it's a zero based zero one, we have now added or inserted Slardie Bart fast. So what if we want to know where something is? Let's say we want to print. I can't type. So we want to know the index of let's say Carl. Why did that return to negative one? Let me play around with this for a minute. Did I misspell something? There we go. So Bob's at the fifth index. Why did that say zero or negative one for Carl? That's weird. Obviously I have a boo boo somewhere. That's interesting. I'll have to figure that one out, but basically index of gives you the position of where they are. Let's actually play with this a little bit here. Figure this out. So we're going to say there's a little function here called for each and what for each we'll do is it will list out every single item in the list. And we're going to say for each. Give me just a second here. This looks like voodoo magic. I will explain this in just a minute. Oh, semicolon expect. Oh, dupe, dupe, dupe, dupe. All right. That's what's going on here. So if you look at our list here, we've got Brian, Slardie Bart fast, space, Heather, space, Chris, space, Carl and Bob. That's the problem. That's what's going on here. Remember how we split it based off of this. So what we should try to do here, what is the name of that? Was it trim? Let's just do this easy way. I'll have to look it up, but I swear there was a function in there. You can do that. Let's remove those. The spaces in there, right? What I was looking for here is name. I'm sorry, names. trim. Trim will remove the blank spaces. I was hoping to do that per item, but I think it's going to be more of an advanced topic. I've also got a cold, so I'm not going to really fight through the cold medicine to do it. So when we run this now, you'll see how there's no spaces in there. And if we go back to putting Carl in there, I think Carl was throwing an air, and so was Heather. You'll see now that it is at position four. So back to this list for each. What in the world are we doing here? So we're taking our list, which is this thing here, and we're saying for each item in the list, and then we're doing an anonymous function, and we want a V or a variable, and we're going to print that. I know this is a bit of an advanced topic for people that are brand new to the language, but those of you, you know, really great iron veterans who have worked with multiple languages are probably loving me for this right now. Just know that you can do these kind of things with Dart language, and that makes it so elegant and so nice. And it makes troubleshooting things a little bit easier too, as you can see. So anyways, finally, maps. Maps are a little bit different. We're going to say map, and we want to give it, once again, we're doing generic programming here. We're going to say string and an int, and we're going to call this ages equal. And what a map is, is you have what's called a key value pair. So we're going to say Brian and 43. Man, am I 43? I'm getting old. I was just playing Call of Duty. That explains some things. Why I was just getting completely smoked on Call of Duty by some of these players. Literally, like I shot a rocket at some guy, and he just laughed at me and like stabbed me in the face of the shovel. So it was not fun. I actually thought about just uninstalling the game at that point. Fortunately for me, though, Carl also plays video games, and he is older than me. So thank you, Carl, for being my friend. Anyways, so what we're doing here is we're actually building a map or a key value pair. Uh oh, somebody's texting me. This looks important. You can wait just a minute. So the key value pair is going to a lineup. We have the key and we have the value. And in here is our actual map. Now, it's called a map because you actually have two lists under the hood. These names are a list or the keys. And these values are a list called values. So let's just say print ages dot keys. You'll see Heather or I'm sorry, Brian, Heather, Carl, Brian, Heather, Carl. Those are the keys. Notice how it's a list. Now let's say print. Whoa, did I hit caps lock? Sorry for yelling at you guys. Print ages dot values. So you can see how we have two distinct lists here. So what a map does is map those or correlate them. This one maps to that one. This one maps to that one. That's why it's called a map. All right, so how do we work with this? How do we really extrapolate data out of this thing? Well, let's say we want to get the value of one of these keys. So we're going to say print pages. And then we're going to say Brian, my throat to get a little sore. I've had this nasty cold. It's just really driving me nuts. So there's 43. So you can see how Brian maps to 43. And we've got the value of Brian using that key. We could also do something like this. And we can say ages dot keys at element zero. So we want to get the first one. Whoops, maybe that isn't really working well. Isn't defined by sure. Really? I thought I could do that. Element at. Let's do it this way because I said so. And it does the same thing, basically. But now I really want to know why I couldn't do this. You think you could do this? Did I screw something up? It's probably because it's got these double blocks, which leads me to my next point. It's just a fairly new language, so things will evolve over time. I expect something like that would actually function at some point. All right, so how do we actually add in here? So we're going to say ages dot oops, actually, let's do let's say ages. Give me a name mark equal marks in his fifties. So we'll say that. Then we can print ages mark. Let's save and run this bad boy. And you can see there's mark in his fifties. Now just for giggles, let's say we wanted to do something like we did with this list here where we do a for each. So we're going to say ages for each. Notice how it has string int fat arrow into void. If you have no idea what I just said, we will cover all of that. I promise you in future tutorials. And for this, we're going to say K and V for key and value. And we of course, because this is all one statement, need to end that with a semicolon. That looks crazy nuts, doesn't it? If you're used to other languages. So what we're going to do here is we're going to say print and then do this. So you can see that for each item in our map, we're saying key is value years old. So Brian's 43 had this 24 on and on and on. Pretty neat, pretty simple. So that in a nutshell is working with variables. And I realized we kind of got off base on a few areas. I apologize. I've got this bad cold medicine going on. But if you ever want to know more, you can definitely go out to the Dart Lang page, dartlang.org, and look at the Dart tour language, excuse me, Dart language tour, and definitely check these out. One other thing you should note is you can click on libraries tour of Dart libraries. And you can see the built in libraries, Dart core as it's called. And you can get much, much more information out of all these things. You can get some really good examples. This is something I really have grown to love about dartlang.org is it has all this information baked right into the webpage. So I don't have to spend five, 10 minutes, you know, looking up on Stack Overflow or Expert Exchange or anything like that. You can get a lot of great info out here. So definitely check this out. That being said, thank you for watching. I hope you found this educational entertainment entertaining. And before you go, the source code for this will be out on voidrumbs.com, also on GitHub actually, there's a link to it on my website. And be sure to check out the voidrumbs Facebook group. There's 1700 other developers out there. And that's it.