Coding

Dart Programming Tutorial – Full Course

  • 00:00:00 [Music]
  • 00:00:04 hey dad is Mohammad Ahsan and welcome to
  • 00:00:07 my dart programming language tutorial
  • 00:00:10 that is the main programming language to
  • 00:00:12 develop cross-platform mobile
  • 00:00:14 application using flatter framework in
  • 00:00:17 this video tutorial I will discuss the
  • 00:00:20 fundamental features of dart programming
  • 00:00:22 language if you know any other
  • 00:00:24 programming language then you will find
  • 00:00:26 out is really easy to understand so no
  • 00:00:29 more talking let's begin to install dart
  • 00:00:33 is decay in your system please visit 8
  • 00:00:35 HT TPS and dart dot div and here you
  • 00:00:39 will see that there is a get dirt link
  • 00:00:43 just click that on that menu and here
  • 00:00:46 you will see there is three version
  • 00:00:48 windows linux and mac so if you are
  • 00:00:50 using Windows just follow the
  • 00:00:51 instruction to install that is decay in
  • 00:00:53 your system as I use Mac so I followed
  • 00:00:57 this Mac instruction and I already
  • 00:00:59 installed dart in my system currently
  • 00:01:01 there is version 2.3 which I am also
  • 00:01:04 using for this lesson as well to write
  • 00:01:09 dart code you can choose any editor but
  • 00:01:11 I personally prefer Visual Studio code
  • 00:01:14 editors so if you want to use Visual
  • 00:01:16 Studio coded or you can install from
  • 00:01:18 this web page and there is also Mac
  • 00:01:21 Windows and Linux version as I'm using
  • 00:01:24 Mac so I install the Mac version also if
  • 00:01:28 you do not want to install the dart SDK
  • 00:01:31 or the Visual Studio code editor in your
  • 00:01:34 system you just want to check out dirt
  • 00:01:36 by just typing the code in a wave editor
  • 00:01:39 you can just use the dart pet so the
  • 00:01:42 address is dark pet dot dot length over
  • 00:01:45 G here you will see this interface and
  • 00:01:47 for example here is the main function
  • 00:01:49 and suppose here I write print hello
  • 00:01:51 world one and I just click run and you
  • 00:01:54 two will show compile the program and
  • 00:01:56 show the output in the right side window
  • 00:01:59 so if you want you can also use this
  • 00:02:01 dart pet but I personally prefer to use
  • 00:02:04 Visual Studio code editor and run dart
  • 00:02:07 code in the system so currently I open
  • 00:02:11 my Visual Studio code
  • 00:02:13 and here you will see the visual code
  • 00:02:15 editor and to highlight the scene tip
  • 00:02:19 you should install a dart extension to
  • 00:02:22 instruct that extension in the visual
  • 00:02:24 code is studio code editor you have to
  • 00:02:26 click view then here you will see
  • 00:02:28 extension just click on it and here you
  • 00:02:32 if you search dart you will see that
  • 00:02:35 three point one point zero there is an
  • 00:02:37 extension which I already installed so
  • 00:02:39 if you are using Visual Studio code
  • 00:02:41 editor you just find out this dart
  • 00:02:44 extension and click in stand and it will
  • 00:02:46 be installed in your visual is – code
  • 00:02:48 editor and then if you click view
  • 00:02:50 Explorer then you will see this
  • 00:02:52 interface as well
  • 00:02:53 so currently I created this playground
  • 00:02:56 dot d R AR T so dot code extension is da
  • 00:03:01 R T so I created this playground or dart
  • 00:03:04 file in my desktop demo directory where
  • 00:03:07 I will write some code and execute in
  • 00:03:09 the terminal so if you do not see any
  • 00:03:12 terminal window in Visual Studio code
  • 00:03:14 editor just click terminal and then
  • 00:03:16 click new terminal so here you will get
  • 00:03:19 the current directory location
  • 00:03:21 automatically so if I want to run this
  • 00:03:24 playground dot dot so what I have to
  • 00:03:27 type d AR teetered and then the file
  • 00:03:30 name so playground dot dot in my case
  • 00:03:33 and if I click run I I can see the
  • 00:03:35 output of the program here so I do not
  • 00:03:39 need to open this terminal window
  • 00:03:42 separately I just you I just can use
  • 00:03:45 this built-in terminal feature in Visual
  • 00:03:48 Studio code editor
  • 00:03:50 [Music]
  • 00:03:54 dart is a static type programming
  • 00:03:57 language it is also a compiled
  • 00:03:59 programming language so it static type
  • 00:04:02 means if you defined a variable as
  • 00:04:04 string you cannot assign other values
  • 00:04:07 like integer or double on that is
  • 00:04:09 king-type variable though there is an
  • 00:04:11 exception like there is a type called
  • 00:04:14 dynamic which you can use to store any
  • 00:04:17 kind of values I will discuss that on
  • 00:04:19 later another thing is that that
  • 00:04:21 supports two type of compilation one is
  • 00:04:24 called a or T or ahead of time another
  • 00:04:27 is called JIT or just-in-time
  • 00:04:30 compilation so when we want to run a
  • 00:04:33 dart program we have to compile it and
  • 00:04:36 then run but it happens automatically so
  • 00:04:40 when we write a dart program and we just
  • 00:04:44 run it automatically complex on the fly
  • 00:04:47 and this is called just-in-time
  • 00:04:48 compilation and when we deploy our final
  • 00:04:52 product then it will be compiled as a Oh
  • 00:04:55 T or a dove term time compilation with
  • 00:04:58 some optimization let's write a dart
  • 00:05:03 program so every dot program starts with
  • 00:05:06 a with the main function so let's write
  • 00:05:09 a main function void main so your main
  • 00:05:13 is a function and what means this
  • 00:05:16 function returns nothing if you want you
  • 00:05:18 can avoid this void so it is optional so
  • 00:05:22 that means if there is no return type
  • 00:05:24 that is called this function does not
  • 00:05:26 return anything so let's define a
  • 00:05:30 variable so I type for first name and
  • 00:05:34 here I assigned my name Mohamed and then
  • 00:05:39 suppose I want to define another
  • 00:05:41 variable last name so in this case I
  • 00:05:44 will type string last name asan and now
  • 00:05:48 I want to print this so first name then
  • 00:05:51 last name so if I here I have to put a
  • 00:05:56 plus sign for string concatenation and
  • 00:06:00 if I want to run this program I have to
  • 00:06:02 type dot playground
  • 00:06:04 TRT Harry here you will see the output
  • 00:06:07 Mohamed is space asan so what does it
  • 00:06:10 happen in here so the first line number
  • 00:06:13 two here I define a variable is in the
  • 00:06:16 VAR keyword so var means a variable and
  • 00:06:19 the variable name is first name what I
  • 00:06:21 have assigned Mohammed as the failure so
  • 00:06:24 when you define a variable like this way
  • 00:06:27 dart compiler automatically gets that
  • 00:06:30 this is a string type very values
  • 00:06:33 because and this is called type in for
  • 00:06:36 inference and in the second type a
  • 00:06:39 second line the third line we define the
  • 00:06:42 variable as easting type and which we
  • 00:06:44 mentioned it in the before so if you
  • 00:06:47 defined a variable like this way that is
  • 00:06:51 string last then you cannot assign other
  • 00:06:53 vidoes like if i type two it will show
  • 00:06:55 an error but in the first case if I type
  • 00:06:57 two here it will not show an Iran in
  • 00:06:59 here because in that case it will
  • 00:07:02 understand that this is a integer value
  • 00:07:05 so you have to remember this thing in
  • 00:07:08 dart programming language that it
  • 00:07:09 supports both type inference and is
  • 00:07:13 statically typed defined so when we type
  • 00:07:17 dark playground or DRT there is just in
  • 00:07:20 time compilation happens so this code
  • 00:07:22 will compile on the fly and then it will
  • 00:07:25 run and we can see the output in that
  • 00:07:27 terminal if there will be an erode we
  • 00:07:29 can see that error also in here
  • 00:07:32 another thing is that all the built-in
  • 00:07:34 dart libraries like a built-in types
  • 00:07:38 collection and other poor functionality
  • 00:07:40 for every dot program basically is
  • 00:07:42 defined in a package that is called dart
  • 00:07:46 door Pullen core package so if you want
  • 00:07:50 to import you have to type this the
  • 00:07:51 import then single quote dot : then core
  • 00:07:56 package but the thing is that if I run
  • 00:07:59 this program again nothing will be
  • 00:08:01 changed
  • 00:08:02 it will run as usual but the thing is
  • 00:08:04 that this dart colon core package
  • 00:08:07 automatically imported so for these case
  • 00:08:10 or normal cases we do not need to import
  • 00:08:12 this dot colon core pack is it will be
  • 00:08:15 imported in every dart program autumn
  • 00:08:18 ethically so let's write another program
  • 00:08:20 in this program we want to take input
  • 00:08:22 from users so for this input output
  • 00:08:25 operation we have to import a library
  • 00:08:28 that is called IO libraries so I have to
  • 00:08:31 import then dart : io and now let's
  • 00:08:36 write a main function and here I want to
  • 00:08:41 first show user that you have to type
  • 00:08:44 your name so I I have to write a code
  • 00:08:46 like it standard out dot write line and
  • 00:08:50 here I will write what is your name and
  • 00:08:55 then a question mark and then I will
  • 00:08:58 take the input from user so for this
  • 00:09:01 reason I will type string name and then
  • 00:09:04 standard in dot read line sync and then
  • 00:09:10 I will print that name so my name is
  • 00:09:15 dollar name so let's run this program
  • 00:09:19 first so you see in this condition what
  • 00:09:25 is your name if I type mode ASSA you
  • 00:09:30 will be seeing that it is showing my
  • 00:09:33 name is Mohammad Ahsan so basically this
  • 00:09:36 is standard out and is standard in this
  • 00:09:38 library is defined in this dart : io
  • 00:09:42 package so the first line we are showing
  • 00:09:44 you that that by writing standard out
  • 00:09:47 dot write line that means it this line
  • 00:09:50 is shown in the terminal then in this
  • 00:09:53 line is standard in dot read lancing
  • 00:09:55 this when at the program found this line
  • 00:09:58 it will wait for the user to give an
  • 00:10:00 input so when we get the input from user
  • 00:10:02 we assign that variable which is a
  • 00:10:05 string in this named variable and
  • 00:10:07 finally we just using the built-in print
  • 00:10:10 method or print function to output the
  • 00:10:13 name in the terminal and here you will
  • 00:10:16 see in within the estream we are using a
  • 00:10:18 dollar sign and the variable name so
  • 00:10:20 this is called a sting interpolation so
  • 00:10:23 within the easting we change a variable
  • 00:10:25 with the real value we can write common
  • 00:10:31 in Treece
  • 00:10:31 / a boy in dark tip in a dart program so
  • 00:10:35 if you want to write a comment in line
  • 00:10:37 then you have to use two forward slash
  • 00:10:40 that is called inline comment if you
  • 00:10:42 want to write block comment then you
  • 00:10:44 have to use forward slash star and you
  • 00:10:46 have to in the common using another is
  • 00:10:48 turn forward slash so here we can write
  • 00:10:51 multiple line of comment and another
  • 00:10:55 comment is three forward slit is called
  • 00:10:57 documentation so that will be used as a
  • 00:10:59 document for your program
  • 00:11:04 [Music]
  • 00:11:08 there are two type programming language
  • 00:11:11 one is called strongly typed another is
  • 00:11:13 called dynamic type so in strongly typed
  • 00:11:15 programming language like C++ Jabbar
  • 00:11:17 sweep the type of a variable is known at
  • 00:11:20 compile time and another type
  • 00:11:23 programming language that is called
  • 00:11:24 dynamic type like Python Ruby or
  • 00:11:26 JavaScript in these programming
  • 00:11:28 languages the type of a variable is
  • 00:11:31 known at runtime so in dart programming
  • 00:11:35 language there are five basic type like
  • 00:11:38 int double string Bowl and dynamic this
  • 00:11:41 fourth type are fundamental type and
  • 00:11:43 dynamic is a dynamic type that means we
  • 00:11:46 can change the value at runtime with
  • 00:11:50 different type values so in this example
  • 00:11:54 let's define a variable so int for
  • 00:11:57 integer amount 1 is the variable name
  • 00:11:59 where we have s and 100 then in the
  • 00:12:02 second line we have defined var amount
  • 00:12:05 to 200 so in this case the by using the
  • 00:12:09 VAR keyword we define a variable amount
  • 00:12:10 2 so L it is 200 that is an integer
  • 00:12:14 value so the dart compiler automatically
  • 00:12:17 knowns knows that that this is a integer
  • 00:12:20 value and integer variable so dart
  • 00:12:24 compiler make this amount to an integer
  • 00:12:26 so next time if we SN other value like
  • 00:12:29 double or sting in this amount o it will
  • 00:12:31 shown an ero and the third line we have
  • 00:12:34 just been this amount 1 and amount 2
  • 00:12:37 then we define another variable using
  • 00:12:39 double and put a double value and then
  • 00:12:42 in the second cases we have defined the
  • 00:12:47 double variable but using the VAR
  • 00:12:48 keyword so the variable value type will
  • 00:12:52 be determined at the compile time then
  • 00:12:56 you also print that value as well then
  • 00:12:59 we define another variable name 1 which
  • 00:13:02 is a string type we define in by
  • 00:13:05 mentioning string and in that second
  • 00:13:07 cases we using we define name to a
  • 00:13:11 distinct variable using VAR cured but
  • 00:13:13 here the type inference occurred here we
  • 00:13:16 define
  • 00:13:16 easy true 1 using the bull key or that
  • 00:13:19 is a boolean type variable where we have
  • 00:13:22 assigned true this is a boolean value
  • 00:13:24 and then using the Warka we define
  • 00:13:27 another variable is it true to where we
  • 00:13:29 define false video which is also a
  • 00:13:31 boolean value so both of these variable
  • 00:13:34 are boolean type and finally we define a
  • 00:13:38 variable weight variable and where we
  • 00:13:41 have used our key we use the keyword
  • 00:13:43 dynamic so this week variable is a
  • 00:13:45 dynamic type variable so the value value
  • 00:13:49 type can be defined at the rendezvous at
  • 00:13:51 the first time we have assign 100 and
  • 00:13:54 the second type we have assigned dart
  • 00:13:56 programming which is a history and the
  • 00:13:58 first time it was a integer so let's run
  • 00:14:01 this program we see that this program is
  • 00:14:09 run perfectly well so here we see that
  • 00:14:12 amount 1 100 amount to 200 this line
  • 00:14:15 this pin line is printed in here then we
  • 00:14:18 printed the floating point values using
  • 00:14:20 this line print so we are seeing that
  • 00:14:22 these values is also painted correctly
  • 00:14:24 here we are using this my name is this
  • 00:14:27 thing is also painted in here and we can
  • 00:14:30 see this true and fall this two variable
  • 00:14:32 the boolean type variable values are
  • 00:14:34 also painted in here perfectly well and
  • 00:14:37 finally this dynamic type week variable
  • 00:14:39 which we have SN 100 it is printed in
  • 00:14:42 here and the next time we change the
  • 00:14:44 value of this week variable as string
  • 00:14:46 type ways we have seen that this is also
  • 00:14:49 printing correctly that means this week
  • 00:14:51 variable which is dynamic type we can
  • 00:14:54 assign any type of value at any time so
  • 00:14:57 this is the prim fundamental or
  • 00:14:59 primitive type in dart programming
  • 00:15:01 language and one thing you have to
  • 00:15:02 remember the dart is an object-oriented
  • 00:15:05 programming language and everything is
  • 00:15:07 object in here even the null type so now
  • 00:15:11 that means if we assign here week
  • 00:15:13 variable and just put now that means
  • 00:15:15 there is nothing and if I just type
  • 00:15:18 print week variable in this case and
  • 00:15:21 let's try to run this program and you
  • 00:15:25 see it is showing now so even this null
  • 00:15:27 type is also an object so everything is
  • 00:15:31 object in dart programming
  • 00:15:33 where this integer value this variable
  • 00:15:36 everything is object even this function
  • 00:15:38 is also an object which is a subtype of
  • 00:15:41 the function class
  • 00:15:44 [Music]
  • 00:15:48 we can define a string variable using
  • 00:15:51 single quote or double quotes so if you
  • 00:15:53 start defining a string using single
  • 00:15:56 core you have to in that easting using
  • 00:15:58 single code as well the same rule is
  • 00:16:00 applied for double quotes as well so
  • 00:16:03 here is one is define a string variable
  • 00:16:05 using single quote and h2 is define
  • 00:16:07 using double quote in the s3 variable we
  • 00:16:10 using a single quote and we also want
  • 00:16:12 that there is an apostrophe within the
  • 00:16:15 each keyword so in this case we have to
  • 00:16:17 use a backward slash to separate this
  • 00:16:20 single code within the string but if we
  • 00:16:22 are just using this double core to
  • 00:16:25 define a system we can just replace this
  • 00:16:28 special character by just single code
  • 00:16:31 and finally if you want to define a
  • 00:16:34 Royston roistering mean if there is a
  • 00:16:36 special character that is newline
  • 00:16:38 character suppose it will not be
  • 00:16:40 evaluated so to define a roy string you
  • 00:16:43 have to just put a are in front of the
  • 00:16:45 string so let's run this program you see
  • 00:16:50 the single quote this string is printed
  • 00:16:52 double chorus ting is also printed and
  • 00:16:55 here it's you see that this apostrophe
  • 00:16:57 is showing here nicely also for the s4
  • 00:17:01 variable as well and in the final case
  • 00:17:03 our Royce ting you see this newline
  • 00:17:05 character is not evaluated because it is
  • 00:17:07 defined as Royston by using the R in
  • 00:17:11 front of the string string interpolation
  • 00:17:16 means to replace a variables value
  • 00:17:19 actual value within a string so here we
  • 00:17:22 have defined a variable age where we
  • 00:17:23 have assigned 35 an integer value and in
  • 00:17:27 the second string variable we replace
  • 00:17:29 this age a variables value within the e
  • 00:17:33 string by using this dollar sign so that
  • 00:17:35 means when you want to interpolate in a
  • 00:17:38 easting just use the dollar sign in
  • 00:17:39 front of the variable name within a
  • 00:17:41 string so if we run this program we see
  • 00:17:43 the output is showing correctly that my
  • 00:17:45 age is 35 we can define multi-line
  • 00:17:50 string in dart programming language
  • 00:17:52 using either three single quotes and
  • 00:17:54 ending with three single cores or is
  • 00:17:56 starting with three double quotes and
  • 00:17:58 ending with three double course if
  • 00:17:59 run this program you see it issuing the
  • 00:18:03 multi-line string in the terminal type
  • 00:18:07 conversion is a very important topic in
  • 00:18:10 any programming language sometimes we we
  • 00:18:13 need to convert an e string to an
  • 00:18:15 integer and sometimes we need to convert
  • 00:18:17 an integer to string to convert an e
  • 00:18:21 string to an integer value you can use
  • 00:18:23 the parse method of int objects so here
  • 00:18:27 we are passing and string one and this
  • 00:18:30 method part will convert this string one
  • 00:18:33 to an integer one and assign that value
  • 00:18:36 in this one variable in the next line we
  • 00:18:39 are using the built-in a search function
  • 00:18:42 to verify that so here we are verifying
  • 00:18:45 that if one equal to integer one if it
  • 00:18:48 is not true then it will show an ero in
  • 00:18:51 the terminal similarly if we want to
  • 00:18:54 convert an E string to double we can use
  • 00:18:57 the parse method defined in that double
  • 00:18:59 object so let's run this program you see
  • 00:19:02 there is no problem no erode issuing
  • 00:19:05 that means this parsing or cut correctly
  • 00:19:07 but if we want to change the easting
  • 00:19:10 like this string there is known no
  • 00:19:13 integer value within this string then
  • 00:19:15 what happened let's write this program
  • 00:19:17 you see it is showing an ero that this
  • 00:19:22 parse method try to convert this easting
  • 00:19:24 to an radix 10 number but it is it found
  • 00:19:28 that there is STR character so that
  • 00:19:31 means it cannot convert this STR to an
  • 00:19:34 integer value there so it will be thrown
  • 00:19:37 an e roll and this exception is called
  • 00:19:41 format exception so you have to make
  • 00:19:44 sure that if you want to convert an
  • 00:19:47 integer or double value string value to
  • 00:19:50 an integer or double primitive value
  • 00:19:53 then you have that easting with that
  • 00:19:56 integer or double value similarly if we
  • 00:20:02 want to convert from integer to e string
  • 00:20:06 we can use that here 1.2 string method
  • 00:20:11 so that means as I said before that
  • 00:20:13 every
  • 00:20:13 thing in dart programming language is an
  • 00:20:16 object so that means here the new
  • 00:20:19 Merrillville one is also an object so we
  • 00:20:23 can use this to string method of that
  • 00:20:25 object so here we are typing 1.2 string
  • 00:20:28 and we are converting this integer value
  • 00:20:31 to an e string value and assign this in
  • 00:20:33 one an E string variable and in later we
  • 00:20:37 also using this pi values that is double
  • 00:20:40 value to a string so here we have to use
  • 00:20:44 two e string as fixed two so here
  • 00:20:46 basically we want to convert this for
  • 00:20:49 floating point number two to fixed point
  • 00:20:52 floating point numbers so let's run this
  • 00:20:55 program and you see there is no error so
  • 00:21:01 that means this one integer is converted
  • 00:21:04 to as easting which we are verifying in
  • 00:21:06 here by putting single quote outside of
  • 00:21:09 one that means it's an e string and it
  • 00:21:12 asserted correctly similarly here we
  • 00:21:15 converted this double value to two fixed
  • 00:21:18 point double string so and we are
  • 00:21:22 verifying here that if this is as string
  • 00:21:26 with two fixed point
  • 00:21:28 fixed point number and we found that yes
  • 00:21:30 it is also asserted correctly in here so
  • 00:21:34 that means three point one point four
  • 00:21:35 now is in string value so this is how we
  • 00:21:39 can convert any type to any type in dart
  • 00:21:42 programming language when we define a
  • 00:21:48 variable we can define that variable as
  • 00:21:51 a constant type that means during the
  • 00:21:53 run then we cannot change the value of
  • 00:21:55 that variable so to define a variable as
  • 00:21:58 constant in dart programming language we
  • 00:22:01 have to use the keyword Const so here we
  • 00:22:04 have defined a variable a constant and
  • 00:22:06 this is an integer constant because
  • 00:22:09 there I have put a zero with an integer
  • 00:22:12 so by type inference the compiler will
  • 00:22:15 make this variable as integer constant
  • 00:22:18 similarly a countable is a boolean
  • 00:22:20 constraint and a consisting is an in
  • 00:22:22 this string constant then we are
  • 00:22:25 printing these three very
  • 00:22:26 and also the next three line we are
  • 00:22:29 checking the runtime type that means
  • 00:22:31 what type the compiled created during
  • 00:22:35 the runtime so let's around this program
  • 00:22:39 you see where we are seeing zero true a
  • 00:22:42 cons string and the type is int bool and
  • 00:22:45 easting so this is how we can define
  • 00:22:48 constant type in dart programming
  • 00:22:50 language
  • 00:22:52 suppose we defined a variable like int
  • 00:22:55 and Nam and did not assign any value
  • 00:22:59 within this variable if we just use the
  • 00:23:01 print function and try to print the
  • 00:23:05 value of this norm variable let's run
  • 00:23:07 this program and see what is shown in
  • 00:23:09 the terminal it is showing that there is
  • 00:23:11 null that means there is no value
  • 00:23:14 assigned in this variable so you have to
  • 00:23:16 keep in mind that if you define a
  • 00:23:18 variable or object but did not assign
  • 00:23:21 any very values on it that means that
  • 00:23:24 then empty so it is it contains the null
  • 00:23:29 object we can also externally use null
  • 00:23:33 in this case so if I run this program
  • 00:23:35 again you see there is no change so that
  • 00:23:38 means if we did not explicitly assign
  • 00:23:41 null value within a variable it
  • 00:23:43 automatically assigned if there is no
  • 00:23:45 real value assigned to this variable
  • 00:23:49 [Music]
  • 00:23:53 if you know other programming language
  • 00:23:56 like JavaScript C++ Swift or Python all
  • 00:24:00 the standard operators will work in dart
  • 00:24:04 programming language so for example if
  • 00:24:06 you want to add two videos you can just
  • 00:24:08 use the plus sign for negative – you can
  • 00:24:11 use minus sign for if you want to see
  • 00:24:15 that if there is any reminder or not you
  • 00:24:17 can use the modulus operator that is
  • 00:24:19 also called percentage operator in some
  • 00:24:22 programming language and if you want to
  • 00:24:25 check relational video like if two
  • 00:24:28 values are equal or not love for example
  • 00:24:30 here using this if logic we are checking
  • 00:24:33 that if num equal to zero or not then
  • 00:24:36 print zero for not equal to you can use
  • 00:24:39 not equal to this operator and for
  • 00:24:42 greater than or equal to you can use
  • 00:24:43 this greater than an equal sign and less
  • 00:24:45 than an equals and for less than or
  • 00:24:47 equal to operator
  • 00:24:48 if you want to use in short of a
  • 00:24:52 shortcut value like for example if for
  • 00:24:55 here we are using num multiplication
  • 00:24:57 equal to 2 it means that I want to
  • 00:25:00 assign nom equal to num multiplied by 2
  • 00:25:03 for example here we are using this
  • 00:25:05 shortcut 0 so we put this multiplication
  • 00:25:08 value in here in front of the equal sign
  • 00:25:11 and and then we are passing 2 that means
  • 00:25:13 this is num equal to num x 2 similar t
  • 00:25:18 thing you can use using the plus minus
  • 00:25:20 like that and a dot programming language
  • 00:25:24 also supports unary operator that means
  • 00:25:27 you can if you use C++ Java or
  • 00:25:30 JavaScript you can use this even Aereo /
  • 00:25:32 – like + + num just means that increment
  • 00:25:36 nom value one by one you can this is
  • 00:25:40 called post in cream a pre increment and
  • 00:25:42 this is called post in khammam post
  • 00:25:44 increment both are unary operator and
  • 00:25:46 you can also use another shortcut video
  • 00:25:48 like plus equal 1 similar similar to
  • 00:25:52 this in re operator and for logical
  • 00:25:55 operator you can use this double
  • 00:25:57 ampersand sign so that means this
  • 00:25:59 logical and and for logical order you
  • 00:26:01 can use this double
  • 00:26:03 bar sign so in Python we use this we use
  • 00:26:07 only n and or the the physical the
  • 00:26:10 English cure like n and and and or in
  • 00:26:14 Python but in JavaScript in dart we can
  • 00:26:17 use this logical and and logical or
  • 00:26:20 operator to make two condition bills in
  • 00:26:23 within an if statement so here we are
  • 00:26:26 writing a code like if num greater than
  • 00:26:28 200 and nom less than 200 3 then print
  • 00:26:32 200 – 200 – so the here we can use the
  • 00:26:35 logical and operator and in this case
  • 00:26:37 both of this part and this part should
  • 00:26:40 be true to make this thing happen for
  • 00:26:43 not equal to operator we can just use
  • 00:26:46 this sign and then equal sign so if I
  • 00:26:49 run this program you see everything is
  • 00:26:53 showing currently in the terminal null
  • 00:26:58 our operator is one of the important
  • 00:27:00 operator in dart programming language
  • 00:27:03 basically this kind of operator is
  • 00:27:06 existed in many modern programming
  • 00:27:08 languages like Swift cortland and in
  • 00:27:12 dirt there are three variation of this
  • 00:27:14 operator so let's discuss so suppose we
  • 00:27:18 want to define a class so in this class
  • 00:27:25 nom there is a property we declare that
  • 00:27:28 is another num and where we have
  • 00:27:30 assigned 10 and let's define the main
  • 00:27:33 function so here I want to create an
  • 00:27:37 object of this class num so far in equal
  • 00:27:41 to no so to create object of a class in
  • 00:27:44 dart programming language you just have
  • 00:27:46 to use the class them and the
  • 00:27:47 parentheses then the object will be
  • 00:27:49 automatically created so an instance of
  • 00:27:52 this num class is created and SN in this
  • 00:27:55 variable that is n so n is an object of
  • 00:27:58 norm class let us define another
  • 00:28:01 variable so what we actually want we
  • 00:28:06 want to assign this value in this number
  • 00:28:10 variable suppose this kind of value
  • 00:28:13 comes from another
  • 00:28:15 area suppose we are using an API from
  • 00:28:19 this API we get this kind of a JSON
  • 00:28:22 object and the JSON object maybe they
  • 00:28:24 are exists available and we want to get
  • 00:28:26 that number so we have to make sure that
  • 00:28:29 this in object is not null so how we do
  • 00:28:32 that normally what we write if in not
  • 00:28:36 equal to null then number equal to n dot
  • 00:28:41 num and just print the number so
  • 00:28:46 normally it's a common programming
  • 00:28:47 practice that we check that if the
  • 00:28:49 object is not now then Excel the object
  • 00:28:52 properties like it here so if I run this
  • 00:28:55 program dart playground you see it is
  • 00:29:02 working perfectly
  • 00:29:07 suppose this an object is not we remove
  • 00:29:11 this num last name and if I run this
  • 00:29:14 program again you see it is showing this
  • 00:29:18 number has a null object so there is
  • 00:29:22 nothing basically when this n object is
  • 00:29:25 now this thing will not Excel but if I
  • 00:29:28 just remove this F word and if I run
  • 00:29:32 this program again you see now there is
  • 00:29:36 an error thrown that is no such method
  • 00:29:38 either so basically we are excesses in
  • 00:29:42 dot num but n is now that's why it will
  • 00:29:45 thrown an error and the program will
  • 00:29:47 terminate in here so there is a shortcut
  • 00:29:50 in a dart programming language language
  • 00:29:54 using that we can avert this if
  • 00:29:56 statement so what we have to write we
  • 00:29:59 just have to write instead of n dot num
  • 00:30:03 we have to write in a question mark then
  • 00:30:06 door then num so if I run this program
  • 00:30:09 again you see in this case it is showing
  • 00:30:14 nothing because there is no n object in
  • 00:30:20 object is now that's why this thing is
  • 00:30:22 not work and number equals now that is
  • 00:30:25 shown in here and if there is an object
  • 00:30:28 suppose we put in the we create an
  • 00:30:31 object in here the instance of num class
  • 00:30:33 and if I run this program again you see
  • 00:30:36 now it is showing tin so the number is
  • 00:30:38 10 so basically this null our operator
  • 00:30:41 means that if there is an object so if n
  • 00:30:45 is an object and if the object property
  • 00:30:49 naam is accessible then just do it so
  • 00:30:52 that means if n is an object and if n is
  • 00:30:56 an valid object then excess the property
  • 00:30:58 named num and assign the value from num
  • 00:31:01 to here but if the N is not an object if
  • 00:31:05 n is a null object then just escape this
  • 00:31:10 there is another variation of this null
  • 00:31:13 operator so in case if this n is not
  • 00:31:18 a valid object there there is nothing
  • 00:31:21 happen in here right the number will
  • 00:31:24 remain null as it is defined but what we
  • 00:31:27 want if the aim object is null we want a
  • 00:31:31 default value help to be s any number so
  • 00:31:33 how we can do that the shortcut way to
  • 00:31:36 do that is you use a double question
  • 00:31:38 mark and assign a default value for
  • 00:31:40 example we want to default values 0 so
  • 00:31:44 let's save this program and run again so
  • 00:31:50 now you see that when we run this
  • 00:31:52 program the number is printing as 0 that
  • 00:31:56 means when this part is null then this
  • 00:32:00 part will be executed but if we just
  • 00:32:04 again put this num here and if I run
  • 00:32:09 this program again then you see that 10
  • 00:32:11 is printed so that means now N is a
  • 00:32:13 valid object that has a property of num
  • 00:32:16 so that value is SN in here but in case
  • 00:32:19 n is a is not a valid object then in
  • 00:32:21 that case the default video 0 will be as
  • 00:32:25 an in number the third variation of this
  • 00:32:30 knowledge operator is like this suppose
  • 00:32:32 we define a variable number now it is
  • 00:32:34 not if I just print this number and save
  • 00:32:38 this program and run you see it issuing
  • 00:32:41 null but what we want that we want to
  • 00:32:44 make a condition like if the variable or
  • 00:32:48 object is null we want to assign a
  • 00:32:51 default value so what we can do that we
  • 00:32:54 just use double question mark then a
  • 00:32:56 equals sign all together and put a
  • 00:32:58 default value if I run this program
  • 00:33:00 again you see now it is showing 100 if I
  • 00:33:05 run this program after the first print
  • 00:33:07 statement you see the number 100 is
  • 00:33:15 showing in the second case as well so
  • 00:33:16 here it is happening is that the when
  • 00:33:19 the number is not a valid object that
  • 00:33:21 means the number is now then this 100
  • 00:33:24 will be assigned in this variable and
  • 00:33:27 that is permanent ok so you have to keep
  • 00:33:30 in keep mine
  • 00:33:32 in this Chi variation of the nollie or
  • 00:33:34 operator because if you do not check now
  • 00:33:38 sometimes your program may care so if
  • 00:33:41 you know this not a reporter and you can
  • 00:33:44 if you can use it wisely then it can
  • 00:33:46 save in many cases in your program
  • 00:33:49 there is another operator called ternary
  • 00:33:52 operator in JavaScript C C++ Java so
  • 00:33:57 that opera is also existed in dart
  • 00:33:59 programming language so for example here
  • 00:34:01 we define a program int x equals 100 and
  • 00:34:05 var result equals x reminder to equal to
  • 00:34:09 0 so that means if we want to define
  • 00:34:14 this 100 I mean the value of x by 2 so
  • 00:34:18 if there is any reminder and if that
  • 00:34:21 remainder is 0 then pin this event but
  • 00:34:24 if the remainder is not 0 then print or
  • 00:34:26 so in the next time we are printing the
  • 00:34:29 result so if I run this program you see
  • 00:34:32 in this case it is printing even because
  • 00:34:35 x equals 100 which is devided which is
  • 00:34:39 reminded by 2 and there is no remainder
  • 00:34:42 so that means this condition made and
  • 00:34:45 the first part of the of this ternary
  • 00:34:49 operator is executed but if I just make
  • 00:34:52 it suppose 101 and run this program
  • 00:34:55 again you see now this condition is not
  • 00:34:59 met that's why this odd is printed there
  • 00:35:03 is a type test operator in dart
  • 00:35:06 programming language for example let's
  • 00:35:08 define a variable integer X equal 100 or
  • 00:35:12 maybe var X equal 100 so we want to know
  • 00:35:17 that if what if X is an integer type
  • 00:35:21 then just pin something so how we can
  • 00:35:23 write that program so we have to type if
  • 00:35:25 then X is int then print integer
  • 00:35:34 so let's save this program and run you
  • 00:35:39 see if this condition is true that means
  • 00:35:43 we want to check that whether the
  • 00:35:44 variable of X is integer type that's why
  • 00:35:48 we have written that if X is in that
  • 00:35:51 means if X is an integer then print in
  • 00:35:53 design and it is true but if we change
  • 00:35:56 the value to suppose a double value and
  • 00:35:58 if I run this program again then this
  • 00:36:01 condition is not true that's why we did
  • 00:36:04 not see any integer is printed in the
  • 00:36:06 terminal sometimes we want to write a
  • 00:36:11 program with some condition that means
  • 00:36:13 if a certain condition is true then do
  • 00:36:16 something and if certain condition is
  • 00:36:18 false then don't do something so in a
  • 00:36:22 dart programming language we can write
  • 00:36:24 conditional code using if else if and
  • 00:36:27 else operator so that means here let's
  • 00:36:30 define a program first we define a
  • 00:36:33 variable into the number equals 100 so
  • 00:36:37 then we are using the remainder operator
  • 00:36:39 we are checking that if this condition
  • 00:36:41 is true that means if this number is
  • 00:36:43 divided by 2 with no dividend that means
  • 00:36:46 equal to 0 then print even if not then
  • 00:36:51 if it is divided by 3 then print odd and
  • 00:36:55 E in other cases that means if this
  • 00:36:58 first condition is not true second
  • 00:37:01 condition is not to the default cases
  • 00:37:03 then pilled confused so let's run this
  • 00:37:05 program first so here it is showing even
  • 00:37:09 then I am I put here 90 and it is
  • 00:37:16 showing even again so if I put here 91
  • 00:37:22 it is showing confused so in this
  • 00:37:27 scenario the first condition when made
  • 00:37:30 then the second and third condition that
  • 00:37:32 means yourself and each block will not
  • 00:37:34 be executed but if this block is not
  • 00:37:39 true then the then the program will
  • 00:37:41 check this block if it is not true then
  • 00:37:43 it will check the default block so this
  • 00:37:45 is how we can write a fields if
  • 00:37:47 and it's condition in that program there
  • 00:37:51 is another way we can write if is a
  • 00:37:53 statement in dart programming language
  • 00:37:56 and in this case we we have to use the
  • 00:37:58 switch statement
  • 00:37:59 so basically switch works similar like
  • 00:38:02 if-else condition so here we are
  • 00:38:05 defining a variable number where we have
  • 00:38:07 SN way to 0 and then in the switch
  • 00:38:10 statement within the parentheses we are
  • 00:38:12 checking this number variable and within
  • 00:38:15 the curly braces this is the body of the
  • 00:38:16 switch statement we are checking that if
  • 00:38:19 the value of this variable E is 0 then
  • 00:38:22 print this and break then break from
  • 00:38:24 this switch statement in case this
  • 00:38:27 condition is not true then check this
  • 00:38:29 condition if case equals 1 then do this
  • 00:38:32 thing and break from the switch
  • 00:38:34 statement if no none of the case is true
  • 00:38:38 then just a do the default condition so
  • 00:38:41 here let's run this program it is
  • 00:38:45 showing even because this condition made
  • 00:38:47 so if I put here one and save this
  • 00:38:49 program and run you see now it is
  • 00:38:52 showing or because this condition is not
  • 00:38:54 made that's why this condition made
  • 00:38:56 that's why it is showing here but in
  • 00:38:58 case if I put different pedal and run
  • 00:39:02 this program
  • 00:39:03 it is showing confuse because 0 and 1 is
  • 00:39:06 not made this condition is not mean
  • 00:39:09 that's why the default condition is
  • 00:39:11 executed looping means we want to
  • 00:39:19 execute a task for a finite number of
  • 00:39:22 time repeatedly so there are basically
  • 00:39:24 five kinds of dope in dart programming
  • 00:39:27 language so the first loop is the
  • 00:39:29 standard for loop is 10.4 dough it's
  • 00:39:35 similar like in JavaScript so for
  • 00:39:37 example we want to print one to ten mmm
  • 00:39:42 so how we can do that let's write F is
  • 00:39:44 standard for loop so you have to pass by
  • 00:39:46 four then within parenthesis let's
  • 00:39:49 declare a variable var I equals 1 then
  • 00:39:52 semicolon this is the first part that
  • 00:39:54 are initialized part then we write the
  • 00:39:57 condition I there is in equals to 10 so
  • 00:40:00 as long as I list they're not equals to
  • 00:40:02 tame then run this loop and then the
  • 00:40:06 increment or decrement part so here I
  • 00:40:08 have written pre increment plus plus I
  • 00:40:12 so these are the increment or decrement
  • 00:40:15 / so that means and the wind ax this
  • 00:40:18 program is run this part will be
  • 00:40:19 executed first then it will check the
  • 00:40:22 condition in here and after and then the
  • 00:40:25 body will be executed then the program
  • 00:40:29 goes to here and increment the value of
  • 00:40:33 I and then check the condition again if
  • 00:40:35 the condition is true then it will break
  • 00:40:37 from the loop otherwise it will continue
  • 00:40:39 the loop so if I just put print I and
  • 00:40:42 run this program you see it is showing 1
  • 00:40:47 to 10 so this is the standard for loop
  • 00:40:51 there is another for loop that is called
  • 00:40:54 for in loop suppose we have an array so
  • 00:40:59 far numbers we define a variable number
  • 00:41:02 and using the square bracket it is a
  • 00:41:06 shortcut that means it's an array we
  • 00:41:08 define some videos within this array 1 2
  • 00:41:11 3 and we want to print all of this video
  • 00:41:14 so using for in loop we can do it easily
  • 00:41:16 so here we are writing for then var in
  • 00:41:20 in numbers and within the body print and
  • 00:41:25 so here it is meaning that for part in
  • 00:41:31 in number so the value of n will be
  • 00:41:34 first time 1 second time – and third
  • 00:41:37 time 3 it will be executed as long as
  • 00:41:40 the array contains some pillows so if I
  • 00:41:43 run this program you see this wing 1 2 3
  • 00:41:48 so this is the standard for in loop if
  • 00:41:51 we want to use this array using the
  • 00:41:55 standard follow we can do that also for
  • 00:41:58 example for VAR I equals 0 I less then
  • 00:42:03 numbers dot length then plus plus I and
  • 00:42:07 here print numbers I
  • 00:42:13 so if I run this program you see in this
  • 00:42:18 case one two threes again printed
  • 00:42:20 because we are using the standard four
  • 00:42:23 loop there is another loop that is
  • 00:42:27 called for each loop so basically for
  • 00:42:31 each n higher order function so for
  • 00:42:35 example here like before we have defined
  • 00:42:39 an array with and some integer values so
  • 00:42:42 we want to print that each of this video
  • 00:42:45 right so we can do that using numbers
  • 00:42:48 dot for each and then here we have to
  • 00:42:52 define a function so for example we want
  • 00:42:56 to access each of these video right so
  • 00:42:58 we can do that like in and then we can
  • 00:43:02 use an arrow function what is the arrow
  • 00:43:04 function I will discuss later we can
  • 00:43:07 also use a normal function here as well
  • 00:43:09 but in this case it looks elegant too is
  • 00:43:13 error function and we just write code
  • 00:43:16 like this way if I run this program
  • 00:43:17 again you see it is showing or sorry
  • 00:43:24 here I have the I did a mistake it have
  • 00:43:26 to be it has to be in so if I run this
  • 00:43:29 program you see one two three is
  • 00:43:31 printing so basically this for each is
  • 00:43:34 an higher-order function because it
  • 00:43:37 takes another function as parameter this
  • 00:43:41 full thing is actually a function but we
  • 00:43:43 have written in the short from that is
  • 00:43:45 called arrow function I will discuss
  • 00:43:48 this thing in later in the functional
  • 00:43:50 part but just keep in mind that there is
  • 00:43:53 another way for looping especially in
  • 00:43:56 array or object using the for each loop
  • 00:44:00 if you think this arrow function looks a
  • 00:44:04 bit complicated for you you can do
  • 00:44:05 another thing you can define another
  • 00:44:07 function like world print num and here
  • 00:44:11 is a parameter and just print this num
  • 00:44:15 and now instead of this arrow function
  • 00:44:19 just past this Nam function print down
  • 00:44:22 function reference and if I run this
  • 00:44:25 program again
  • 00:44:27 you see the same output one two three
  • 00:44:30 basically we are passing this function
  • 00:44:32 as a parameter of this for each
  • 00:44:34 higher-order function there is another
  • 00:44:37 loop or the number four types of loop is
  • 00:44:40 called while loop suppose we have
  • 00:44:42 defined a variable name equals five and
  • 00:44:44 we want to print the value of num unless
  • 00:44:47 it is zero so we have to write while
  • 00:44:50 then the condition within parenthesis
  • 00:44:52 that Nam get at this zero so as long as
  • 00:44:54 num greater than zero executes the body
  • 00:44:57 and then we first printing the value of
  • 00:45:00 now and then we decrease the value of
  • 00:45:02 num by one if I run this program you see
  • 00:45:08 it is showing nothing because I did not
  • 00:45:10 save so let's run again then you see
  • 00:45:13 that it is showing five four three two
  • 00:45:15 one
  • 00:45:19 there is another variation of this while
  • 00:45:22 loop so instead of using the condition
  • 00:45:25 before we have to write do in here and
  • 00:45:27 after the body caller basis you can
  • 00:45:31 write the condition the while condition
  • 00:45:32 after this curly braces so if I run this
  • 00:45:37 program again you see the same output
  • 00:45:41 five four three two one if within a loop
  • 00:45:47 for a certain condition we want to
  • 00:45:50 terminate the loop we can do this do
  • 00:45:53 this by using break statements so here
  • 00:45:56 in this loop this loop will run ten
  • 00:45:59 times but here we have written a
  • 00:46:01 condition if I greater than five then
  • 00:46:04 just break otherwise print I if I run
  • 00:46:06 this program you see zero to five is
  • 00:46:10 printed and then when the value of I
  • 00:46:13 becomes C that is the it is greater than
  • 00:46:15 5 then this break statement executed and
  • 00:46:19 the loop is terminated so this is how we
  • 00:46:22 can use break current break statement in
  • 00:46:26 any loop to terminate the loop suppose
  • 00:46:31 we want to write a program to print the
  • 00:46:33 odd numbers or even number so in our
  • 00:46:36 case we want to print the odd number
  • 00:46:39 so we have written a loop I a standard
  • 00:46:43 for loop this loop will run 110 times
  • 00:46:46 and here we have written a condition if
  • 00:46:49 I modulus 2 equal to 0 that means if the
  • 00:46:54 DV after the division if there is no
  • 00:46:57 remainder that means 0 then continue
  • 00:46:59 here continuous statement means that
  • 00:47:01 don't go the remaining statement just
  • 00:47:05 continue from the loop from here if I
  • 00:47:07 run this program you see it is showing
  • 00:47:14 the odd numbers from the range 0 to 10
  • 00:47:18 so here you have seen that 1 3 5 7 9 so
  • 00:47:22 the first time I equals 0 and 0 less
  • 00:47:25 than 10 so 0 remainder 2 equal to 0
  • 00:47:29 there so this condition made true so the
  • 00:47:33 continue statement executed and the and
  • 00:47:36 the loop goes to here so I becomes 1 and
  • 00:47:39 then the condition is again checking if
  • 00:47:42 as 1 is less than 10 and within the body
  • 00:47:46 if one remind that 2 equal to 0 it is
  • 00:47:50 not true that's why this condition did
  • 00:47:52 did not meet for the second time that's
  • 00:47:55 why we have seen this one is printing in
  • 00:47:57 here so this is how this container is
  • 00:48:00 statement wash within a for loop
  • 00:48:02 [Music]
  • 00:48:06 there are three building collection type
  • 00:48:10 in dart programming language least sate
  • 00:48:13 and map so list basically is an ordered
  • 00:48:18 collection of hellos so it is in some
  • 00:48:21 programming language is called array but
  • 00:48:24 in dart programming language it is
  • 00:48:25 called list so suppose we want to define
  • 00:48:30 a list and we can do that using list
  • 00:48:32 class so when we define list L is T and
  • 00:48:38 then we define a variable so that means
  • 00:48:40 this names is an object of list class
  • 00:48:43 and here using the shortcut way that is
  • 00:48:47 means using the square bracket we can
  • 00:48:49 define somewhere like Jack and Jill so
  • 00:48:53 these two are string items within this
  • 00:48:57 list so if we want to access each of
  • 00:49:01 this video we can do that so basically
  • 00:49:03 in list the first item is indexed in 0
  • 00:49:07 the second item is 1 and this is how it
  • 00:49:10 goes so if I want to access the first
  • 00:49:13 item from this list we have to write
  • 00:49:15 print names then square bracket 0
  • 00:49:19 if I run this program you see it is
  • 00:49:23 showing Jack because Jack is instead
  • 00:49:25 within the position or index at zero if
  • 00:49:29 I print one and run the program again in
  • 00:49:33 this case it is showing until if we want
  • 00:49:36 to know the number of element existing
  • 00:49:40 in the list we can use the length
  • 00:49:42 property of the list object so here we
  • 00:49:45 are printing name dot length so let's
  • 00:49:47 run the program you see it is showing
  • 00:49:50 two that means this list object names
  • 00:49:53 contains two items instead of lists if I
  • 00:49:57 just put the heart here and if I run
  • 00:50:00 this program you see it what in this
  • 00:50:03 case the compiler by type inference will
  • 00:50:08 know that this names list is a string
  • 00:50:11 type list item so if I put my cursor in
  • 00:50:14 here you see it issuing list angle
  • 00:50:16 bracket string that means this
  • 00:50:18 names is a risk and it is known in by
  • 00:50:21 that type inference if we want to access
  • 00:50:26 each of this item we can do that by
  • 00:50:29 using any for loop but normally in this
  • 00:50:31 case you can use the for in loop so for
  • 00:50:35 bar in in names and print in so if I run
  • 00:50:43 this program you see Jack and Jill is
  • 00:50:46 printed if I want to use mixed item that
  • 00:50:50 means some videos will be seeing some
  • 00:50:52 hello may be double some videos may be
  • 00:50:55 integer we can do that as well so 10 100
  • 00:50:59 point 1 and if I run this program you
  • 00:51:03 see each of this value is printed and if
  • 00:51:06 I put my cursor in here you see now it
  • 00:51:09 is showing list and with an angle
  • 00:51:11 butthead object but if we want that this
  • 00:51:15 leash should be a string type we can do
  • 00:51:18 that by defining the in strip lacing
  • 00:51:22 this bar by list and within angle
  • 00:51:24 bracket we define is string in that case
  • 00:51:28 if you put any value other than is thing
  • 00:51:30 it will shown an arrow so this is a
  • 00:51:33 statically typed names list that means
  • 00:51:36 you cannot put other type instead of in
  • 00:51:39 string if I run this program you see it
  • 00:51:49 is showing out Jack and Jill so for
  • 00:51:51 statically typed list you can just put a
  • 00:51:55 angle bracket after the keyword list and
  • 00:51:58 put the type in here this list is a
  • 00:52:02 mutable type so that means if we want to
  • 00:52:06 change the value of the index 1 we can
  • 00:52:08 do that so names 1 instead of 0 we type
  • 00:52:13 like a mark and if I run this program
  • 00:52:19 you see now it is showing Jack and mark
  • 00:52:22 so the value is replaced with a new
  • 00:52:24 fellow
  • 00:52:24 but if we want to define each of these
  • 00:52:28 value is constant that means we do not
  • 00:52:29 want to change it at run time we can do
  • 00:52:33 that easily by just putting the Const
  • 00:52:36 keyword before the square bracket if I
  • 00:52:39 use this program now and run you see it
  • 00:52:44 is showing an eroded unsupported
  • 00:52:46 operation because you cannot change a
  • 00:52:49 constant value at run time if I remove
  • 00:52:51 this part clear the skin and run the
  • 00:52:55 program again you see there is no error
  • 00:52:58 in that case suppose we want to copy a
  • 00:53:02 list to a another list mmm we can how we
  • 00:53:07 can do that for example let's define
  • 00:53:10 another list or just a VAR names to and
  • 00:53:13 if I just assign these names one I'm in
  • 00:53:17 this next part and if we accept this
  • 00:53:21 name stew and run this program you see
  • 00:53:27 we can still accept the value Jack and
  • 00:53:29 Jill but basically when you assign a
  • 00:53:32 object like list within another object
  • 00:53:35 it's actually not copied instead these
  • 00:53:38 names to accessing the names value so
  • 00:53:42 suppose if I change the value of names
  • 00:53:45 after I selling this suppose I change
  • 00:53:48 the value of names 1 equal to mark and
  • 00:53:52 if I run this program again you see we
  • 00:53:56 get that updated value we are changing
  • 00:53:59 that value repels the value of jail by
  • 00:54:02 mark in the nails variable and we are
  • 00:54:04 looping the names to variable but we can
  • 00:54:07 still see this updated view like Jack
  • 00:54:09 and Martha this is not East election
  • 00:54:11 this is not actually copying rather both
  • 00:54:14 names too and names pointing the same
  • 00:54:16 list of items so instead of doing that
  • 00:54:20 if we want to really clone the list hot
  • 00:54:24 we can do that using our spread operator
  • 00:54:27 in dart 2.3 we can do that easily so
  • 00:54:30 here we just put a square bracket and
  • 00:54:33 then 3 dot and then the first variable
  • 00:54:36 name so names 1 so if I just run this
  • 00:54:39 program again you see in this case when
  • 00:54:44 we looping names too
  • 00:54:45 we are actually getting the old value
  • 00:54:49 Jack and Jill basically in this case
  • 00:54:50 names 2 and names does not point to the
  • 00:54:53 same list of item
  • 00:54:55 both names and names two are totally
  • 00:54:58 different items list items so this
  • 00:55:02 spread operator is similar like
  • 00:55:04 JavaScript I first saw this three dot
  • 00:55:06 spread of water in JavaScript and this
  • 00:55:09 three daughters pet operator is
  • 00:55:10 introduced in dart 2.3
  • 00:55:13 set in dart programming language is an
  • 00:55:17 unordered collection of unique items and
  • 00:55:20 dart support for set is provided by set
  • 00:55:23 literals and the set type so suppose we
  • 00:55:26 defining is said by var keyword var
  • 00:55:31 hello chance and here we have to use the
  • 00:55:34 curly braces and within curly braces we
  • 00:55:37 want to put some string value so we can
  • 00:55:40 type flow Rhine and then chloride to V
  • 00:55:48 Rose so these are basically
  • 00:55:50 unique items if I copied this Florin
  • 00:55:53 again after the comma and if I loop this
  • 00:55:57 program so for VAR x in hello chains and
  • 00:56:02 print X
  • 00:56:04 and if I run this program you see it is
  • 00:56:10 only showing Flores fluorine and
  • 00:56:12 chlorine
  • 00:56:13 so this fluorine if we put it two times
  • 00:56:15 but it is actually stored one time
  • 00:56:18 because by definition set is an unique
  • 00:56:21 collection of items there is another way
  • 00:56:26 to define set if you want to define an
  • 00:56:30 empty set you cannot just put like this
  • 00:56:34 suppose we want to put an empty set hmm
  • 00:56:36 just remove this for loop and remove
  • 00:56:39 these curly braces the items of this
  • 00:56:43 color basis if I just type print hello
  • 00:56:46 jeans run time type and if I run this
  • 00:56:51 program you see in these cases we
  • 00:56:56 thought that it should be set but
  • 00:56:58 instead it become a lint hash map type
  • 00:57:03 hmm so if you want to define a empty set
  • 00:57:08 if you want to define an empty set you
  • 00:57:10 must have to define the type time in
  • 00:57:14 here like you have to put if I just put
  • 00:57:17 a string here with an angle bracket now
  • 00:57:21 you see it is showing has said so just
  • 00:57:24 empty curly braces means hash map but
  • 00:57:27 when you are define a type before the
  • 00:57:29 caliber then it did become a hash set
  • 00:57:34 and another way to define hash set is
  • 00:57:37 like this that using the set key word
  • 00:57:41 that means set class is in the set class
  • 00:57:44 then you can also put this string thing
  • 00:57:46 in here say it string and then if I put
  • 00:57:50 in names and curly braces and if I check
  • 00:57:54 the names runtime type you see it is
  • 00:57:59 also headed so either way you can define
  • 00:58:02 an empty has set in dart programming
  • 00:58:06 language in that programming language
  • 00:58:09 map basically is a collection of
  • 00:58:13 key-value pair of items in some
  • 00:58:16 programming language like in Python
  • 00:58:18 it is called dictionary so let's define
  • 00:58:22 a map in dart programming language so
  • 00:58:24 here I have defined F map gift and the
  • 00:58:28 key of each of the item is a string so
  • 00:58:31 here I have defined within single quote
  • 00:58:34 fast which by this key we are putting
  • 00:58:38 value petrus then say again tart laughs
  • 00:58:41 and filled golden links if I want to
  • 00:58:44 access each of this item we can do that
  • 00:58:46 easily like print gifts and this is also
  • 00:58:51 an ordered and if we want to access any
  • 00:58:54 of this value we have to use the key so
  • 00:58:56 for example here I am I want to use the
  • 00:58:58 key fifth and if I run this program you
  • 00:59:04 see it is showing golden rings so this
  • 00:59:05 is how we can create map in that
  • 00:59:08 programming language another thing is
  • 00:59:10 that you can also use integer value SK
  • 00:59:12 for example to one tree and in this case
  • 00:59:17 we also remove this fifth and instead we
  • 00:59:20 just put one and run this program you
  • 00:59:23 say you see that it also works without
  • 00:59:27 any issue if you want to define an empty
  • 00:59:32 set
  • 00:59:32 sorry if you want to define an empty map
  • 00:59:35 you can do that using the map class so
  • 00:59:39 here we are defining gift as aim and we
  • 00:59:42 want to the created an instance of map
  • 00:59:45 in here and SN in the gifts and now we
  • 00:59:48 want to add key value pairs by ourself
  • 00:59:53 we can do that by easily like gifts then
  • 00:59:56 within square bracket we can put the key
  • 00:59:59 suppose here first as a key and the
  • 01:00:02 value of suppose mango and if I run this
  • 01:00:06 program gives fast
  • 01:00:12 you see it works so this is how we can
  • 01:00:15 create a map in that programming
  • 01:00:19 language another way we can do that
  • 01:00:21 using a curly braces and in there we
  • 01:00:26 have to put the key and the Velo
  • 01:00:27 together for example here fast
  • 01:00:30 and within after : we have to put like
  • 01:00:33 mango the Velo then another key
  • 01:00:35 so this basically key and this is the
  • 01:00:38 video so this 2 item becomes a key will
  • 01:00:41 appear as a one item within the map so
  • 01:00:44 in the second key we want to put another
  • 01:00:47 video like jackfruit and now we want if
  • 01:00:51 we want to access any of this video like
  • 01:00:54 gifts second and if I run this program
  • 01:00:59 you see it is showing jackfruit so this
  • 01:01:02 is how we can create a map in that
  • 01:01:06 programming language in dart programming
  • 01:01:13 language each function is an object of
  • 01:01:17 class function where F is the capital
  • 01:01:20 later so let's define a function for
  • 01:01:23 example we want to defining a function
  • 01:01:24 as a square which we can use to e Square
  • 01:01:28 any integer or num type any integer or
  • 01:01:32 double value so for this reason we want
  • 01:01:34 the return type should be dynamic so
  • 01:01:37 when you define a function at the first
  • 01:01:40 first part you have to define that type
  • 01:01:43 which it will return if there is this if
  • 01:01:46 a function does not return anything you
  • 01:01:48 can use void or you can escape the void
  • 01:01:51 which means it does not return anything
  • 01:01:53 so in this case we are putting dynamic
  • 01:01:56 then the function name is square we also
  • 01:01:58 take any hello so this function can take
  • 01:02:02 parameter so if we want to if you want
  • 01:02:06 that a function take parameter we have
  • 01:02:08 to define there so here we are defining
  • 01:02:09 part number this function will take a
  • 01:02:12 parameter as num and this function will
  • 01:02:16 return the naam into num so whatever we
  • 01:02:19 pass any valid integer or double value
  • 01:02:22 in this square function it will multiply
  • 01:02:25 that by
  • 01:02:26 the same value and return the value so
  • 01:02:29 let's define another function for
  • 01:02:31 example what show output and here we
  • 01:02:36 take an a define a variable as parameter
  • 01:02:40 of our message so this function takes
  • 01:02:42 message as parameter and using the
  • 01:02:45 built-in print function it will pin the
  • 01:02:49 messages in the terminal
  • 01:02:51 so now let's call this function first
  • 01:02:55 show output and within this function we
  • 01:03:01 want to use this function square so here
  • 01:03:05 we are typing Square where we are
  • 01:03:07 putting 2 if I run this program you see
  • 01:03:13 it is showing 4 then we use the same
  • 01:03:17 statement but in this case we are
  • 01:03:19 putting to 0.5 and just run this program
  • 01:03:21 you see now it is showing four and 6.25
  • 01:03:25 as we define this function this a square
  • 01:03:29 function as dynamic so that means this
  • 01:03:31 function can return any type of num
  • 01:03:34 value like any type of integer or double
  • 01:03:37 value and another thing if I just type
  • 01:03:40 print and square this function name we
  • 01:03:44 without parenthesis and runtime runtime
  • 01:03:48 type and let's run this program you see
  • 01:03:53 this is showing there this function
  • 01:03:56 square is a dynamic type in dart
  • 01:04:01 programming language there is a shortcut
  • 01:04:04 way to defining a function which is a
  • 01:04:07 one-line statement so for example here
  • 01:04:11 in dart programming language you have to
  • 01:04:13 use the equal sign and greater than sign
  • 01:04:17 together to make a arrow this is called
  • 01:04:20 fat arrow and sometimes called fat arrow
  • 01:04:22 expression so here we define a full
  • 01:04:25 function write the dynamic square Varnum
  • 01:04:28 and within curly braces we define a body
  • 01:04:31 we can make it we can make it shorter
  • 01:04:34 using arrow function so instead of this
  • 01:04:36 just remove this arrow part
  • 01:04:39 and return part and just put a arrow
  • 01:04:44 here so here what we are defining that
  • 01:04:48 dynamic square Varnum then arrow
  • 01:04:51 expression now multiply numb so when you
  • 01:04:54 write an arrow function like this way
  • 01:04:56 the result of the value after the
  • 01:04:59 competition will automatically return so
  • 01:05:02 if I save this program and run again you
  • 01:05:06 see this program works as like before a
  • 01:05:10 function that has no name or in short
  • 01:05:14 you can call nameless function is called
  • 01:05:17 anonymous function in dart programming
  • 01:05:19 language in some other programming
  • 01:05:22 language like in Python it is called
  • 01:05:24 lambda or in some programming language
  • 01:05:27 it is called closer so here let's define
  • 01:05:31 a list with some string values of I TM
  • 01:05:34 and we want to use the for each function
  • 01:05:38 of this list so let's type list dot for
  • 01:05:43 each this is a higher-order function
  • 01:05:46 because for each function cat can take
  • 01:05:49 other function as parameters within the
  • 01:05:51 body we will define a anonymous
  • 01:05:55 functions of before defining anonymous
  • 01:05:58 function in here less definite named
  • 01:06:00 functions so suppose I am defining a
  • 01:06:02 function void print F which take a
  • 01:06:06 parameter item and just using the print
  • 01:06:10 built-in function it just print the
  • 01:06:15 value of the item variable in the screen
  • 01:06:18 and here we just want to pass this
  • 01:06:21 printf function as reference so if I run
  • 01:06:24 this program you see it issuing Apple
  • 01:06:27 bananas and orange but in this case or
  • 01:06:30 sometimes when you define a forest
  • 01:06:33 function with a shorthand function then
  • 01:06:35 in many cases computer programmers do
  • 01:06:39 not define a named function instead they
  • 01:06:41 prefer to use anonymous function within
  • 01:06:44 the places so to do that let's carve
  • 01:06:51 this part
  • 01:06:53 and remove the named function part and
  • 01:06:57 here remove this printf and put that
  • 01:06:59 thing in here
  • 01:07:01 so if I save this program clear the
  • 01:07:05 screen and run the program again you see
  • 01:07:08 it works so that means this function is
  • 01:07:12 an anonymous function because this
  • 01:07:15 function does not have any name there
  • 01:07:20 are two types of parameters in function
  • 01:07:24 in dart programming language like Python
  • 01:07:26 programming language so one type of
  • 01:07:29 parameter is called positional parameter
  • 01:07:32 or positional argument and the second
  • 01:07:34 type is called named parameter or named
  • 01:07:36 argument so let's see the positional
  • 01:07:40 argument or positional parameters first
  • 01:07:42 so here we are defining an arrow
  • 01:07:44 function which takes two parameter so in
  • 01:07:48 this case we are using the positional
  • 01:07:51 arguments so here num1 is the first
  • 01:07:53 position number the second third
  • 01:07:55 position and we just returning after
  • 01:07:59 combining the value if I run this
  • 01:08:01 program you see it worse it is showing
  • 01:08:04 for now here if you look carefully you
  • 01:08:13 see that when we call this some method
  • 01:08:15 we just passing the value and we expect
  • 01:08:18 that this 2 will be assigned in num1 and
  • 01:08:21 these two will be a zani num2 because we
  • 01:08:23 are using the positional argument on or
  • 01:08:26 positional parameter let's convert this
  • 01:08:29 function this error function to named
  • 01:08:32 parameters so in that case we have to
  • 01:08:34 use the curly braces here so we want
  • 01:08:39 that this 2 parameter should be as named
  • 01:08:41 parameter and when I put curly braces in
  • 01:08:44 here you see it is showing red color in
  • 01:08:47 here so if I just remove this theme and
  • 01:08:50 if I call some now you see that it is
  • 01:08:53 showing num1 and num2 if I put num for
  • 01:08:57 example in this case if I want to put
  • 01:08:59 num2 fast so I have right written num2
  • 01:09:03 colon then suppose for
  • 01:09:06 then I want to put naam one supposed to
  • 01:09:09 if I save this program and run this
  • 01:09:11 again you see it is showing six so when
  • 01:09:15 you are using named parameter you have
  • 01:09:18 to use the name of the parameter when
  • 01:09:21 you are calling the function and this
  • 01:09:24 basically works for not only arrow
  • 01:09:27 function but also for a general function
  • 01:09:31 another interesting thing of name
  • 01:09:35 parameter is that by default named
  • 01:09:38 parameter is optional and we can also
  • 01:09:42 mix positional parameter and named
  • 01:09:44 parameter together for example in this
  • 01:09:46 case we want to change a bit we want
  • 01:09:49 that the num2 is only named parameter
  • 01:09:52 but the Nam one is positional parameter
  • 01:09:54 and num2 may be optional right so in
  • 01:09:59 this case when we want to call this
  • 01:10:01 function sum then we have to put the
  • 01:10:09 value as the first parameter suppose I
  • 01:10:12 am putting tin and as this name
  • 01:10:15 parameter for this name parameter I used
  • 01:10:19 the name num2 and suppose i put two and
  • 01:10:22 if i run this program you see it is
  • 01:10:26 showing 12 but i told before that when
  • 01:10:31 you define a variable sorry when you
  • 01:10:33 define the parameter as named parameter
  • 01:10:36 by default that is optional that means
  • 01:10:38 if you do not provide any value for num2
  • 01:10:42 it should work right but it is crashing
  • 01:10:47 why we defining this num2 parameter as
  • 01:10:51 optional by defining this as a named
  • 01:10:55 parameter but when there is no value but
  • 01:10:59 we are still accessing this value so as
  • 01:11:02 this num2 may be optional what we can do
  • 01:11:05 we can write a conditional nah-nah our
  • 01:11:10 operator like double : 0 so if I if I
  • 01:11:15 change this modification in here and if
  • 01:11:17 I run this program again
  • 01:11:20 you see it is also showing and erode
  • 01:11:23 because I think I have to put a
  • 01:11:27 parenthesis to give the priority and now
  • 01:11:31 if I run this program again you see
  • 01:11:33 there is no error so in this case when
  • 01:11:35 we do not provide the named parameter
  • 01:11:37 value and in the function body we are
  • 01:11:40 checking that whether num2 is null or
  • 01:11:43 not if it is now then just past the
  • 01:11:45 default value as 0 otherwise if there is
  • 01:11:49 any value just used there so if I again
  • 01:11:52 use this statement print and some and
  • 01:11:56 here I put another value 10 2 and num2
  • 01:12:06 so you see it is showing 10 and 12 if
  • 01:12:11 you want that if no value is provided we
  • 01:12:15 can use any default value so instead of
  • 01:12:17 using this we can do a shortcut default
  • 01:12:22 value parameter so here after Nam – we
  • 01:12:25 put a equal sign and put a default value
  • 01:12:29 so if we change this function here and
  • 01:12:31 if I run this program again you see
  • 01:12:34 there is no error because when there is
  • 01:12:36 no parameter no value for num2 parameter
  • 01:12:40 it is using the 0 in here so 0 + 10 that
  • 01:12:44 is 10 and when we pass any value like 2
  • 01:12:48 then in this case the default value will
  • 01:12:50 not be used and 10 + 2 will be 12 so
  • 01:12:54 this is showing in here I told that by
  • 01:12:58 definition name parameter are optional
  • 01:13:01 right but if you are using a positional
  • 01:13:04 parameter and you want to make any of
  • 01:13:07 them as optional then how you can do
  • 01:13:09 that so for example here we want to make
  • 01:13:12 this numbers optional but this is a
  • 01:13:15 positional argument or positional
  • 01:13:17 parameter so to make it optional we just
  • 01:13:21 have to put a square bracket outside of
  • 01:13:23 the parameter and now this num to become
  • 01:13:27 optional so if I run this program
  • 01:13:31 you see it issuing for n2 said the first
  • 01:13:34 time we are passing two values and the
  • 01:13:36 second time we are passing one value so
  • 01:13:38 in that case that nom to become null and
  • 01:13:41 here as we are using null our operator
  • 01:13:44 so that default value zero will be used
  • 01:13:46 in the second case
  • 01:13:49 [Music]
  • 01:13:53 in object-oriented programming class is
  • 01:13:56 a very important topic using class we
  • 01:13:59 can define our own custom type we can
  • 01:14:03 encapsulate the related values and
  • 01:14:06 related methods together and when you
  • 01:14:09 define a class you can inherit to make
  • 01:14:11 some subclass also you can do some other
  • 01:14:16 thing like you can use polymorphism you
  • 01:14:18 can reuse your object-oriented code for
  • 01:14:21 other purpose so in dart programming
  • 01:14:24 language we can create a custom type
  • 01:14:26 using the class keyword so let's define
  • 01:14:29 a class so here we are defining a class
  • 01:14:32 named person so to define a class in
  • 01:14:35 dirt you have to use the keyword class
  • 01:14:36 then the class name and within curly
  • 01:14:39 braces we are defining the body
  • 01:14:42 so basically class is a blueprint for an
  • 01:14:46 actual object this is not object this is
  • 01:14:49 we are defining the type that means we
  • 01:14:52 are defining a person class or person
  • 01:14:55 type and later in the main function we
  • 01:14:58 will use the object of this person class
  • 01:15:01 so in this person class or blueprint we
  • 01:15:05 want that a person should have a name a
  • 01:15:08 person should have a is just basic to
  • 01:15:11 type ok and now let's define a method in
  • 01:15:17 here so when you define a function
  • 01:15:19 within a cloud that is called method so
  • 01:15:22 here we are defining a method void this
  • 01:15:25 function or this method returns nothing
  • 01:15:27 and then show output of function name
  • 01:15:32 which is called method M in the context
  • 01:15:34 of class and this method does not take
  • 01:15:37 any parameter and it just print the
  • 01:15:39 value of name and age
  • 01:15:43 and now let's create an object so here
  • 01:15:48 we can create object into oil of suppose
  • 01:15:51 we want to use this person name in here
  • 01:15:55 so person class name in here and then
  • 01:15:58 person 1 and then person so when you
  • 01:16:04 use the parentheses after the class name
  • 01:16:07 basically it will instantiate an object
  • 01:16:09 and assign that object to this person
  • 01:16:11 one object variable right so if I just
  • 01:16:15 want to excel this show output method I
  • 01:16:18 can write person 1 dot show output
  • 01:16:24 basically it will print nothing I mean –
  • 01:16:28 now if we want to exist this variable
  • 01:16:31 name and age we can do that like person
  • 01:16:34 1 dot name suppose my name Muhammad and
  • 01:16:38 person 1 dot H my suppose 35 so if I run
  • 01:16:48 this program again it is showing
  • 01:16:50 Muhammad and 35 now let's create another
  • 01:16:55 person object but before that we want to
  • 01:16:58 use a constructor which is called
  • 01:17:00 default constructor so what is that so
  • 01:17:03 let's define a constructor
  • 01:17:05 so basically constructor is also a
  • 01:17:09 method without any return type so an in
  • 01:17:12 dart programming language you have to
  • 01:17:14 use the class name as constructor name
  • 01:17:16 so here we are want to defining a
  • 01:17:19 constructor and constructor method is
  • 01:17:22 automatically automatically called when
  • 01:17:25 you instantiate an object so here in
  • 01:17:28 this case we want to pass two parameter
  • 01:17:31 is string name and the second parameter
  • 01:17:35 is optional int age and by default it
  • 01:17:38 should be 18 if there is no age is
  • 01:17:41 provided and as this name parameter name
  • 01:17:46 and the class properties name are same –
  • 01:17:49 if you want to accept the objects or
  • 01:17:52 instance of field we in this case we
  • 01:17:56 have to use the disc keyword
  • 01:17:57 this means this objects name or this
  • 01:18:00 object is also we can call this using
  • 01:18:04 this we can also call the method define
  • 01:18:08 within the class so here we want to use
  • 01:18:09 this dot name equals name and this dot
  • 01:18:13 is equals a so if any name
  • 01:18:16 age is provided when we create the
  • 01:18:17 instance of a class we'll pass the
  • 01:18:21 values and the village will be assigned
  • 01:18:22 the object or instance fields so now
  • 01:18:25 when we define the constructor you see
  • 01:18:28 now it is showing an error because it
  • 01:18:30 expect that I have to pass at least one
  • 01:18:33 name so here I just passed suppose
  • 01:18:37 Mohammed and after saving the program if
  • 01:18:41 I run this program if sedition Mahmoud
  • 01:18:44 and 18 because I did not pass any age
  • 01:18:48 that's why it is taking that default
  • 01:18:50 value but if I pass any as like 35
  • 01:18:55 you see now addition mama
  • 01:18:58 35 so this is called default constructor
  • 01:19:01 another shortcut way to write a
  • 01:19:05 constructor basically constructor is
  • 01:19:08 using to assign some values when the
  • 01:19:11 class instance is created if the
  • 01:19:13 parameter name is same as the properties
  • 01:19:17 or fields name within the class we can
  • 01:19:20 use the shortcut oiseau instead using
  • 01:19:23 this body we can just use here this dot
  • 01:19:28 name and here these dot is and a default
  • 01:19:35 value so if I run this program again you
  • 01:19:39 see it works and in case if I do not
  • 01:19:41 want to provide this 35 and run this
  • 01:19:44 program again you see it works again it
  • 01:19:46 is showing Mohammed 18 so if in your
  • 01:19:49 constructor other than initializing the
  • 01:19:52 values you want to do something is if
  • 01:19:54 there is no other thing you want to do
  • 01:19:57 with in the constructor body you can
  • 01:19:59 skip that curly braces part and only use
  • 01:20:02 this way to shortcut the constructor
  • 01:20:05 let's define another object so in this
  • 01:20:08 case I am going to using the VAR keyword
  • 01:20:10 and person 2 and I give the person I
  • 01:20:13 want to name check and the age is
  • 01:20:17 suppose 25 and let's parse on 2 and call
  • 01:20:21 the show output method
  • 01:20:24 let's clear the screen Andreas from the
  • 01:20:26 program you see in the Fosca it is
  • 01:20:29 showing Mohammed 18 in the second case
  • 01:20:30 it is showing jack 25 so basically this
  • 01:20:34 person 1 and person 2 is totally
  • 01:20:36 different instance of the same class
  • 01:20:38 that is person class and here as we are
  • 01:20:41 using var keyword but in the right side
  • 01:20:44 after equals and we are using the person
  • 01:20:46 class or using the type inference the
  • 01:20:49 compiler the compiler will automatically
  • 01:20:52 know that this person tool basically an
  • 01:20:54 object of the person class other than
  • 01:20:59 default constructor there is another
  • 01:21:01 constructor that is called name
  • 01:21:02 constructor so when you define a
  • 01:21:05 constructor like this where like the
  • 01:21:07 class name as the constructor then this
  • 01:21:10 constructor will automatically that is
  • 01:21:12 why it is called default constructor but
  • 01:21:14 sometimes we may need to instantiate an
  • 01:21:17 object of it as with some different
  • 01:21:19 kinds of values right then how we can do
  • 01:21:22 that there is another way suppose we
  • 01:21:24 want to define a named constructor if
  • 01:21:28 you defined other constructor beside the
  • 01:21:32 default constructor that is called named
  • 01:21:34 constructor to define a name caustically
  • 01:21:36 you have to use the class name so here
  • 01:21:39 person then you have to put a dot and
  • 01:21:41 then the constructor name so we want to
  • 01:21:43 name the constructor as guest and here
  • 01:21:49 we want to assign some values so here
  • 01:21:53 name equal to guest and H equal to 18
  • 01:21:57 okay so let's create another object over
  • 01:22:02 person three person and dot kissed in
  • 01:22:08 this case you see I am NOT passing any
  • 01:22:10 values that's why it is not calling that
  • 01:22:12 default constructor instead it is I am
  • 01:22:16 calling the guest constructor and if I
  • 01:22:19 run this person 3 dot show output method
  • 01:22:25 and run this program
  • 01:22:27 you see in the tort cases it is showing
  • 01:22:30 guests and 18 for the person 3 object so
  • 01:22:33 this is how we can create other
  • 01:22:35 constructor beside default constructor
  • 01:22:42 normally what happened when we define a
  • 01:22:45 variable either explicitly or within a
  • 01:22:48 class we can change the value at any
  • 01:22:50 time if we want right but if we want
  • 01:22:54 that we will define a field or
  • 01:22:56 properties or variable within a class
  • 01:22:59 and that will be unchangeable after
  • 01:23:02 initializing then we can do that by
  • 01:23:04 using the final keyword so here we
  • 01:23:07 define a class class X capital X and
  • 01:23:10 within the class in the body we are
  • 01:23:14 defining a variable named name so and we
  • 01:23:18 are using the keyword final and then we
  • 01:23:21 are defining another variable named age
  • 01:23:25 where we have assigned tane and before
  • 01:23:29 defining the variable we are using the
  • 01:23:32 keyword aesthetic and cons so I will
  • 01:23:34 discuss all of these three thing final
  • 01:23:37 aesthetic and aesthetic Const and then
  • 01:23:41 within the class default constructor we
  • 01:23:43 are just assigning the value passing to
  • 01:23:46 the constructor in the name variable so
  • 01:23:51 let's create an object so far X x
  • 01:23:55 capital F and then pass the value check
  • 01:23:58 hmm and now if I print X dot name and
  • 01:24:03 run this program you see it is swing
  • 01:24:09 check so suppose I want to change the
  • 01:24:14 value of name X dot name equals
  • 01:24:16 something is like Jill and I want to
  • 01:24:20 print the X dot name again
  • 01:24:23 basically it is showing that name can be
  • 01:24:26 used as a setter because it is final so
  • 01:24:29 the dart extension in this visual is to
  • 01:24:32 the code editor can detect that error
  • 01:24:34 but if I just remove this final thing
  • 01:24:37 and just use var name and
  • 01:24:41 on this program you see first time it is
  • 01:24:43 showing jet and the second time it is
  • 01:24:45 showing G so the key point here is that
  • 01:24:49 if you want to define any properties as
  • 01:24:53 a constant you can use the final key
  • 01:24:55 word and using the default constructor
  • 01:24:58 when you assign their value you cannot
  • 01:25:00 change the value after assigning it the
  • 01:25:03 in the second time so only first time
  • 01:25:06 you can assign the value using the
  • 01:25:08 default constructor or any named
  • 01:25:10 constructor
  • 01:25:11 there is two why to define a value when
  • 01:25:15 we defining a variable as constant one
  • 01:25:17 is using final keyword another is using
  • 01:25:19 cost keyword when you are using
  • 01:25:22 concealer that is a compile time
  • 01:25:24 constant it cannot be changed anytime at
  • 01:25:27 or at runtime but when you are using
  • 01:25:29 final keyword within a class you can
  • 01:25:32 change it using the constructor so this
  • 01:25:35 is possible at runtime and if you want
  • 01:25:38 to use any Const constant video using
  • 01:25:41 the constructor within a class you must
  • 01:25:44 have to put a static in front of that
  • 01:25:46 constant in front of that Const variable
  • 01:25:51 so here we are using static cause in
  • 01:25:54 test 10 and if I want to exist the value
  • 01:25:57 of a we can write print X dot H and it
  • 01:26:00 will not work because this is a
  • 01:26:02 compile-time constant and we are using
  • 01:26:04 is in the class and as this is a static
  • 01:26:07 variable we have to use the custom to
  • 01:26:10 access the property and this is called
  • 01:26:11 class property this name is called
  • 01:26:14 object property because this name is
  • 01:26:16 different for different object but the
  • 01:26:19 static property is same for all object
  • 01:26:22 or all instance but that any backup
  • 01:26:24 because it's a class property so here
  • 01:26:27 you have to put the capital X dot age
  • 01:26:29 and if I run this program you see it is
  • 01:26:37 showing ten so suppose I want to create
  • 01:26:39 another object for X suppose VAR y equal
  • 01:26:42 to X and G and Y print
  • 01:26:48 print why dot name and you see that 4x
  • 01:26:58 object and y object the name value is
  • 01:27:01 different but as this property is based
  • 01:27:05 on class so we have to access that
  • 01:27:08 property using the class name dot
  • 01:27:10 property and this is same for all
  • 01:27:12 instance so the age 10 is is same for
  • 01:27:15 both X object and Y object if we want to
  • 01:27:20 use the constant and final outside of
  • 01:27:24 the class we can also do this so let's
  • 01:27:25 remove this class part and remove this
  • 01:27:29 thing and suppose we want to define two
  • 01:27:31 constant videos so final of hard name
  • 01:27:35 suppose the name is something mohamed
  • 01:27:38 and in this case you do not have to use
  • 01:27:41 the VAR because it is this name will be
  • 01:27:44 be a string by type inference and let's
  • 01:27:47 define another below-cost name suppose
  • 01:27:50 age equal to 30 hmm let's print name and
  • 01:27:55 print age and if I run this program
  • 01:27:58 after clearing the terminal you see it
  • 01:28:02 works and we cannot change any of this
  • 01:28:05 name equal to something else cannot
  • 01:28:07 possible also is equal to something
  • 01:28:11 cannot possible it will be shooing and
  • 01:28:14 erode because here you see it is showing
  • 01:28:16 that name is a final variable and age is
  • 01:28:18 also a constant variable which cannot be
  • 01:28:21 reassigned and in this case outside of
  • 01:28:24 the costs both final and constant
  • 01:28:26 actually works like same there is no
  • 01:28:28 difference so you can use anything in a
  • 01:28:32 final or Const outside of the class when
  • 01:28:36 we define a class and later we want to
  • 01:28:39 add some extra feature within the class
  • 01:28:42 but that extra feature is not required
  • 01:28:45 for all the instance of the original
  • 01:28:47 curve then we can use the class
  • 01:28:48 inheritance and in dart program using
  • 01:28:52 the extend keywords you can inherit a
  • 01:28:55 class so here we are defining a class
  • 01:28:58 vehicle where there is two property
  • 01:29:01 modeling here and in the default
  • 01:29:03 constructor we when we pass a model and
  • 01:29:06 year in this default constructor we are
  • 01:29:09 assigning that model value using this
  • 01:29:12 dot model will be in this model and this
  • 01:29:14 dot here the passing air will be as a
  • 01:29:16 linear and within the default
  • 01:29:18 constructor body we are just printing
  • 01:29:20 the model enniaa nothing else and there
  • 01:29:22 is another method Schwab put just it
  • 01:29:25 print the model and here if we want to
  • 01:29:27 use this here that's also okay basically
  • 01:29:30 this means that the instance which it is
  • 01:29:33 called now we are defining another class
  • 01:29:37 class car and that inherit this vehicle
  • 01:29:40 class right by using the extend keyword
  • 01:29:43 and here we are defining a new property
  • 01:29:46 that is called double price and in this
  • 01:29:48 default constructor in the car
  • 01:29:52 constructor what we I do we are taking
  • 01:29:55 three parameter right is string the
  • 01:29:57 string model here and this dot price
  • 01:30:01 here here there is an interesting thing
  • 01:30:04 so the interesting thing is that this
  • 01:30:07 price is the new thing of this car but
  • 01:30:10 disgust as inherit the vehicle so this
  • 01:30:14 model and here also existed within the
  • 01:30:17 car class so what we are doing we are
  • 01:30:21 when we create an instance of this car
  • 01:30:24 class we are assigning the price video
  • 01:30:28 directly in this a variable using the DS
  • 01:30:32 dot price but for the model and here we
  • 01:30:36 want to pass that variable whose using
  • 01:30:39 in the vehicle constructor and to do
  • 01:30:42 that in that you have to use a colon
  • 01:30:44 operator after the parentheses of the
  • 01:30:47 sub class default constructor and you
  • 01:30:49 have to use the super keyword and using
  • 01:30:52 super keyword you have to pass the value
  • 01:30:54 so here when we are calling this after
  • 01:30:57 colonial calling the super then within
  • 01:31:00 pass of the model and here this model
  • 01:31:01 and here will be passed to this
  • 01:31:03 constructor vehicle right so and in this
  • 01:31:07 car cost we are also defining a method
  • 01:31:10 show output and in the show output we
  • 01:31:12 want to call this method that me
  • 01:31:14 super cost method and here we are
  • 01:31:17 calling this super keyword we are using
  • 01:31:20 this super keyword then dot then the
  • 01:31:21 method name so basically super dot schwa
  • 01:31:24 truth means we are calling this method
  • 01:31:25 the superclass method and then we are
  • 01:31:28 printing the discours price now here we
  • 01:31:32 are creating an object car 1 equals car
  • 01:31:35 not vehicle object we are creating a car
  • 01:31:38 one car object we are passing a code as
  • 01:31:40 a model 2014 as the year and 150,000 as
  • 01:31:45 the price and then we are calling car
  • 01:31:47 won't show output so if I run this
  • 01:31:49 program you see it is showing a code
  • 01:31:52 2014 because when the instance of this
  • 01:31:56 card is created then we are calling
  • 01:31:59 basically this car constructor and here
  • 01:32:02 we are passing through here right Accor
  • 01:32:04 2014 and 150,000 so to a code will be in
  • 01:32:08 here 2014 will be here positional
  • 01:32:11 argument and 150,000 will be here and as
  • 01:32:14 we are using this dot price and there is
  • 01:32:17 a property named price as the same name
  • 01:32:19 so this 150,000 will be assigned as the
  • 01:32:22 price of this car and after : on the
  • 01:32:25 default constructor as we are calling
  • 01:32:27 super model here this according 2014
  • 01:32:30 will be passed to this vehicle and will
  • 01:32:32 be as in this model and a year and then
  • 01:32:35 when we call this car one dot show
  • 01:32:37 output you will see this method is
  • 01:32:39 called here we are calling the super
  • 01:32:41 method super cost method show output
  • 01:32:44 where it will be printed model in here
  • 01:32:46 so you see here more than year is
  • 01:32:48 printed and then this price is printed
  • 01:32:52 in here so we are seeing this price in
  • 01:32:54 here so this is how we can our inherit
  • 01:32:57 or extend a superclass to mean to a
  • 01:33:02 subclass method overriding is suppose in
  • 01:33:06 a plus there is a method and in the
  • 01:33:09 subclass it here in Y class extend this
  • 01:33:12 s class we want the same method to
  • 01:33:15 redefine that is called method
  • 01:33:16 overriding if you want that other
  • 01:33:20 programmers know that this method is
  • 01:33:23 overriding you can use add override
  • 01:33:26 annotation so
  • 01:33:27 when you use an override in front of a
  • 01:33:31 method signature that means the compiler
  • 01:33:34 will know that this method is overriding
  • 01:33:36 and in any case there is no method of
  • 01:33:39 the original name it will show an ear or
  • 01:33:42 that method does not overwrite an
  • 01:33:45 inherited method this is basically a
  • 01:33:47 safety feature in dart programming
  • 01:33:50 language when you overriding a method
  • 01:33:53 you if you do not use the override
  • 01:33:56 keyword it will not show an e role there
  • 01:34:00 is no issue for this you have to use
  • 01:34:03 override when you don't have control of
  • 01:34:05 superclass method implementation
  • 01:34:08 basically the intent of the override
  • 01:34:10 notation is to case situation where a
  • 01:34:12 superclass Trinian's a member and
  • 01:34:14 independent subclass which used to
  • 01:34:16 override the member could silently
  • 01:34:19 continue working with the superclass
  • 01:34:21 implementation so the good practice is
  • 01:34:24 if you override a superclass method you
  • 01:34:26 just use the add override annotation
  • 01:34:30 Gators and setters are a special method
  • 01:34:33 that provides read and write access to
  • 01:34:35 an object properties normally each
  • 01:34:38 instance variable has an implicit Gator
  • 01:34:40 process setter if appropriate but if you
  • 01:34:44 want you can create additional
  • 01:34:45 properties by implementing getters and
  • 01:34:47 setters using the gate and set keyword
  • 01:34:50 so here we define a class rectangle
  • 01:34:53 where we are using the NAM object so
  • 01:34:56 basically num means it's an it's a type
  • 01:34:59 and that that is inherited by the
  • 01:35:01 integer and double type so here we are
  • 01:35:04 defining num left top width and height
  • 01:35:07 so the value of left of width and height
  • 01:35:09 can be integer or double and in the
  • 01:35:12 default constructor we are just
  • 01:35:14 assigning the values passed and SN in
  • 01:35:16 the properties now we are defining two
  • 01:35:20 Gators that is right and bottom and two
  • 01:35:23 setter for each of them so to defining a
  • 01:35:26 Gator we are defining a right Gator name
  • 01:35:30 right and use the gate keyword before
  • 01:35:32 the name and then we are providing the
  • 01:35:36 return type and here we are using an
  • 01:35:38 arrow function and it with what it will
  • 01:35:40 do if we
  • 01:35:40 call this right Gator will get left plus
  • 01:35:43 with these two variables data and will
  • 01:35:47 get this value and if we want to make a
  • 01:35:50 satyr we have to use the set keyword and
  • 01:35:53 the setter name so here it is right and
  • 01:35:56 we are passing any value number low and
  • 01:35:58 we are putting the left value so using
  • 01:36:01 the arrow function what we are doing we
  • 01:36:03 are assigning left equals value – which
  • 01:36:06 so we have a – we are passing a failure
  • 01:36:10 right and what we are doing we are doing
  • 01:36:12 a customization so we are we are a –
  • 01:36:16 thing that with value from the value and
  • 01:36:19 that assigning that value in the left
  • 01:36:21 variable within that class similarly we
  • 01:36:24 are doing the same thing as for bottom
  • 01:36:26 and now we are creating an object rect
  • 01:36:28 using the rectangle class name and
  • 01:36:31 passing some values and then we're
  • 01:36:33 printing the Reg dot left hello letter
  • 01:36:35 on this program we are seeing that the
  • 01:36:37 lab value is 3 and then we are par
  • 01:36:40 calling the getter method that is right
  • 01:36:43 so reg dot write equals 12 when we
  • 01:36:46 defining a method we have to use the
  • 01:36:48 parentheses but when we are using the
  • 01:36:50 Gator or setter we do not need to use
  • 01:36:54 any appearances like when we want to
  • 01:36:57 access any Gator we just have to use the
  • 01:37:00 dot operator and when we want to use a
  • 01:37:02 sitter we just call the setter name and
  • 01:37:05 the equal sign and in that case the
  • 01:37:08 value will be assigned as a setter so
  • 01:37:10 here when we are calling red dot right
  • 01:37:13 equals to L so that 12 comes in here and
  • 01:37:16 of hello – so value is 12 and it – we so
  • 01:37:23 with is here that is 20 so value is 12
  • 01:37:28 12 minus 20 equals minus H so that's why
  • 01:37:31 when we are printing reg dot left we are
  • 01:37:34 getting this minus 8 output so this is
  • 01:37:36 how we can define getter and setter in
  • 01:37:39 dart programming language
  • 01:37:41 [Music]
  • 01:37:45 exception handling is a feature in a
  • 01:37:48 programming language by which we can
  • 01:37:50 know that if there is any runtime
  • 01:37:52 problem occurred or not
  • 01:37:54 so in dirt if we want to use exception
  • 01:37:58 handling we can use the throat try catch
  • 01:38:01 finally keyboard so suppose here we are
  • 01:38:04 defining a function must greater than
  • 01:38:06 zero so this function if it gets the
  • 01:38:10 value greater than zero then there is no
  • 01:38:12 problem it will return the value but if
  • 01:38:15 it gets a value equal to zero less than
  • 01:38:19 0 then it will throw an exception and to
  • 01:38:23 throw an exception you have to use the
  • 01:38:24 throw keyword and the exception class
  • 01:38:26 name and within the exception custom you
  • 01:38:28 can provide a message you see the depth
  • 01:38:31 of method definition is swinging and
  • 01:38:33 showing above the cursor if a function
  • 01:38:37 throws in exception you have to catch
  • 01:38:40 that otherwise the program will
  • 01:38:42 terminated so we're defining another
  • 01:38:44 function let verify the value or where
  • 01:38:47 we can pass any value and within the
  • 01:38:50 function we are defining a value
  • 01:38:52 verification variable where we'll SNF a
  • 01:38:54 wasn't of value so as this math function
  • 01:38:58 must greater than zero can throw an
  • 01:39:00 exception so we have to define this
  • 01:39:02 function within that try block so here
  • 01:39:05 is in the try block we are using value
  • 01:39:07 verification e equal mass greater than
  • 01:39:09 zero and we are passing the value so if
  • 01:39:12 there is an e roro card then we are just
  • 01:39:15 printing the error by catching the error
  • 01:39:17 in here cache within the parentheses we
  • 01:39:20 can catch any type of exception here and
  • 01:39:23 then in the finally block which is
  • 01:39:26 basically an optional block we are
  • 01:39:28 checking something like if this value
  • 01:39:30 verification is null because if in any
  • 01:39:33 case if this mul greater than zero
  • 01:39:35 function returns an error then that case
  • 01:39:38 this value verification will be now
  • 01:39:39 right by definition it is null and if
  • 01:39:42 it's success then it will this variable
  • 01:39:45 will get the value so in the finally
  • 01:39:48 block we are checking that if that is
  • 01:39:49 null that we are printing value is not
  • 01:39:52 accepted otherwise we are printing value
  • 01:39:54 verified and the
  • 01:39:56 we're using the sting interpretation we
  • 01:39:57 are passing the Velo so let's run this
  • 01:39:59 program you see in first cases it is
  • 01:40:02 showing volute in but when we in the
  • 01:40:07 second case when we are passing the
  • 01:40:08 values zero in the first case it is
  • 01:40:12 printing will you verified by ten but in
  • 01:40:13 the second case it is this catch block
  • 01:40:17 basically captured this exception that
  • 01:40:20 value must be greater than zero you see
  • 01:40:23 this this message is printing in here
  • 01:40:26 but after the exception word and then in
  • 01:40:30 the finally block we also captured the
  • 01:40:34 value I mean the message and here it is
  • 01:40:36 printed Velo is not accepted basically
  • 01:40:40 when you use the catch keyword and
  • 01:40:42 within the princess you use any
  • 01:40:44 parameter like e it basically handles
  • 01:40:47 all kinds of error but if your program
  • 01:40:50 has a specific type of ero you can use
  • 01:40:52 the on keyword so after the try block
  • 01:40:54 you have to use on then the exception
  • 01:40:56 name then if you have another type of
  • 01:40:59 ero then you can use on and that
  • 01:41:02 exception name and sometimes anything is
  • 01:41:06 that is an exception you can use like
  • 01:41:08 this on exception catch e so this is
  • 01:41:11 another pattern but normally I prefer or
  • 01:41:14 in the most cases I use the try catch
  • 01:41:16 block or try catch finally block I
  • 01:41:19 normally do not use the on exception
  • 01:41:21 thing unless it is very important for
  • 01:41:24 the particular program so I hope that
  • 01:41:28 this tutorial will help you to
  • 01:41:30 understand dart programming language and
  • 01:41:32 you can able to dive deep in flatter
  • 01:41:34 framework if you liked this video please
  • 01:41:37 give a thumbs up and if you have any
  • 01:41:39 question please ask in the comment
  • 01:41:41 section I also welcome you to visit my
  • 01:41:44 personal YouTube channel where I
  • 01:41:45 regularly publish programming related
  • 01:41:47 video tutorials so thank you for
  • 01:41:50 watching and have a nice day