9 Dart concepts to know before you jump into Flutter // for super beginners in Flutter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
H ey everyone welcome back and this video  is for everyone who are looking to start   with flutter but have no idea where  to start with. Well, you should start   with Dart first of course because that is  the language that you need to understand   to even read a Flutter project, forget writing  one! But i have never been a great fan of   long courses because the length bores me and  I'm more excited to jump into the meaty part   of writing my first Flutter application then to go  over a very long course that tells me everything   there is to know! I'm more interested in those  courses only once i have got some progress and I   have and I am at a stage where i need to learn  more concepts to even proceed further but to   start? i need to know just enough to write  my first Flutter application and to be able   to understand the code. And if you're a learner  like me and also looking to start with flutter   you might find this video helpful because i am  going to tell you about the 9 dart concepts that   you need to learn before jumping onto flutter so  without wasting any more time let's get started!! Before we start i need to be sure  that you're ready for this video.   You should only continue this video if  you have some programming experience,   like you know about variable, constants & more  importantly you have some practice with object   oriented programming like C++, java so you're  comfortable with OOP concepts such such as   classes, objects, constructors, methods functions  etc if you have no idea about object oriented   programming i would highly recommend not to jump  the gun here and start directly with Dart. I mean   you could always do that but you will always have  thousand questions about programming in general   and you will have a gap in your knowledge because  this video is not about "learn programming with   Dart" so only continue this video if you have  some practice or have taken some classes of object   oriented programming. so, No 1! and very important  one any dart program would start with void mean   that is the entry point to your dart application  if you've ever created a flood project like this   you would find the same in main.dart as well  now in the void main let's print something into   the console by using the print statement number  two start supports following variables currently   which is numbers which is an int if it's a integer  or a whole number or a double if it's a decimal   or a floating point integer and you can also use  num if your variable could be integer or a double   both next that supports strings of course which  can be written either with a single quote or   a double quote like this but you can't start  a string with a single quote and end it with   a double quote and of course we have booleans  which is a variable that takes either of the   two values which is true or false so if you  have a variable called does pooja like flutter   the value could either be true or false but i  think we all know the correct answer to that   before we move on do you know that we would  actually not specify any type and just use var   for a variable instead of the types that i just  mentioned right now dart is actually smart enough   to know the actual type of the variable once the  value has been set let's see that in action here   we have a variable called i don't know who i am  and i'm going to be setting a variation of values   to this variable and check the runtime  type of this variable and see how smart   dart is now if you print this variable without  any value being set this would print its type   as null so let's give it a string and see if  dart can get that it does yay if we give it an   integer value the runtime type would be integer  and if we give it a double value the runtime type   would be double so that was where if you do not  know what type of value your variable is going   to be moving on we have list if you are coming  from a different programming language you might   be more accustomed to the keyword arrays but here  in dart we call them list so you can create a list   of integer either by completely specifying the  data type and what this list should contain like   here is a list of integer or you can also just  use var and let dart figure it out so of course   you can create a list of the same types but you in  dart you can also create a list of different types   such as here is my list that contains an integer  a string and a double all at the same time so now   you must be wondering what type would this list be  off so if you have a mixed bag of types like this   you could give your type as list of time make next  we have maps which is nothing but a key value pad   have you ever seen a json string that is also  a key value pair where it is a map of someone's   name and job where name could be puja and job  could be flutter developer you could also specify   its type as map of something something here you  have to give two data types which is what should   be the data type of your key and what should be  the data type of your value in this case we have   a map of string and string but in dart we are of  course not limited to that we could actually use   any type of data types it could be a map of  integer or string it could be a map of double   or string it could be map of integer and integer  you get the gist if you're printing the values   you could print the entire map as a key value  pair or you can choose to print just the keys   of the entire map or just the values of the inter  map or maybe a value of a certain key like this   there are other types also available in dart like  sets runes but this is enough to get started with   flutter so let's move on to the next concept so  number three so now you just learned about strings   which i know you knew that already but let's talk  about string interpolation now i don't know which   language you're coming from but you may or may not  know about string interpolation basically let's   again see how we define a string so here we have a  variable called sentence which says hello puja now   all that is fine but this value pooja should come  from a variable instead rather than hard coding it   on the string so you should have variable  something like this that will be inserted into   your string now usually we are habituated with  something like this where we use the plus sign   to add a string and a variable but it can get a  little messy when there are too many variables in   question so there's another way we could do this  in dart which is what string interpolation is all   about where you could actually write the same  thing like this which is much more cleaner when   read and if you have a object or a function that  you also need to insert into your string you could   also wrap them with the curly braces and insert it  into your string just like this moving on we have   functions and i'm sure you know what functions are  it is pretty similar in dart as well like you have   a function like this with no parameters and you  have another function like this with parameters   so usually we call this parameters as  positional parameters because the position   is fixed which means that if your first parameter  is a string and the second parameter is an integer   when you're calling that function you cannot  interchange the parameters and give the first   value as integer and the second value as string  or you can't even skip parameters just like this   but in dot we have a solution we have two more  types of parameters other than the positional   parameters parameters which is the optional  positional parameter where if you think one   of the parameters is optional and not really  required to run the function you could add   that parameter inside square brackets and when  you're calling that function you can choose to   provide the second value or you can choose not  to but something more exciting is the named   parameters so you have this function like this now  if you wrap the parameters inside the curly braces   now this solves two problems which is having  to remember the position of your parameters   because now you just need the name to provide  it the value just like a key value pair so here   when i'm calling the function i can i can  write like name colon puja and age colon   whatever and of course you can interchange  the positions here and the function will work   just fine and the second problem that it solves  that that all the parameters inside the curly   braces are optional so you can also choose  to skip one of the parameters if required or   you can choose not to provide any values at  all number five is checking for null values   so imagine if you have a function that prints if  an item is free of cost or has a price where this   is a function that has a named parameter called  price where it's possible that this value is   not provided to this function when we are calling  this function which means that price will be null   and we are checking if price is null we print free  of cost and if there is a price we print the price   and it works perfectly as you can see here but  it takes six lines of code just to do this simple   task now in dart we have a simpler way of doing  this with null aware operators you print the price   and just after your variable you put two question  marks which is the null aware operators and you   provide a default value so which means that when  we are printing price if this variable turns out   to be null that is going to print the default  value instead of course this default value could   be of any data type so this could also be like  a final price where if price is null the default   value is zero which is an integer with string  interpolation it could look something like this   number six so we reduce the six line code to  two lines with null aware operators but we can   also reduce that into one line in dart with fat  arrow functions or arrow syntax so if we have   such functions which have only one expression in  that function we can reduce them into one line   by using the fat arrow syntax which is just an  equal to sign and an arrow so now this function   becomes wide print price fat arrow and print  statement but if you have a function like this   where there is more than one expression then you  cannot reduce the function into a fat arrow syntax   number seven and this is about classes and since  i already told you that you're supposed to know   about object oriented programming and classes are  an important part of that so you should be aware   of classes and this is how classes look like in  dart and how constructors look like in doubt and   when you are creating the object for its class  and trying to print one of its variable it would   look like this if you are coming from c plus plus  or java or other similar languages this might be   exactly the same as in your language as well but  more importantly is the next one which is number   eight which is constructors in dart classes which  might be different than your current language   like here you see a normal constructor for  that class where we are assigning the construct   constructor argument to the instance variable now  imagine if your class had more than 10 variables   and you had to do the same thing for all these  10 variables but of course that would make this   easier for you where you can remove all these  boilerplate code and just write this instead and   behind the scene start will take care of setting  the instance variables for you but in dot you can   choose to not even write a constructor at all that  way dart will create a default constructor for you   the default constructor will have no arguments and  if we remove the constructor that we just created   in our class right here it will look something  like this and when you're creating an object for   this class it would be like this after creating  the object you can choose to set the values   like this and print it the same way as usual or  when you have a constructor you can wrap them up   with curly braces and it will act just the same as  named parameters or functions where where the same   concepts apply you can set the arguments like the  key value pair they are they are optional and they   are not fixed to position and that we also have  something called a named constructor where you   can name your constructors and give more clarity  of what it does which also means that you can   have multiple constructors in a class like suppose  for our person class we have a normal constructor   but we also have a named constructor called senior  citizen so now if i have to create an object for   a senior citizen so i would use a senior citizen  constructor of the person class number nine which   is nut check for an object now if you don't  initialize your object at all and just create   a person object just like this your person object  is going to be pretty much null because it was not   initialized at all at this point if you try to  print the age for this person object you should   get an error like age was called a null because  person object is null itself so obviously age is   going to also be null to get rid of that exception  you could use this object null check operator   which is a single question mark so you're telling  da that if the object is null do not proceed   the operation further because naturally age is a  part of p and if p is null h will also be null and   of course you can also club it with the null aware  operator and give this entire expression a default   value like this and that's all the nine concepts  that you definitely need to know before you write   your first flutter application but of course  that's not the end to the dart world this is   just a tiny percentage of what dart has to offer  but once you start with flutter and get the hang   of it and you want to know more about the concepts  of tart you can go to this language tour that dart   has in its official website it's great enough  now if you're ready to jump into flutter and   want to know how to get started with flutter  i already have an article right here which   where i had written how to start with flutter that  should give you the rest of the steps let me know   in the comments if you feel ready to start the  flutter after this video today and of course if   you want to connect with me on other social media  platforms you can connect with me here and here   to know about my work and my events and behind  the scenes and i'll see you in the next video
Info
Channel: Pooja Bhaumik
Views: 66,243
Rating: undefined out of 5
Keywords: flutter, dart, 2020, dart concepts, dart datatypes, functions, classes, functions in dart, classes in dart, string interpolation, pooja bhaumik, dash, null aware operators dart, dot operator dart, pooja bhaumik flutter, is flutter worth learning
Id: yOelmLdhJwk
Channel Id: undefined
Length: 15min 21sec (921 seconds)
Published: Wed Dec 23 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.