Master the Dart Language with Null Safety - For Beginners | Rahul Agarwal | Skillshare
Search

Playback Speed


1.0x


  • 0.5x
  • 0.75x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 1.75x
  • 2x

Master the Dart Language with Null Safety - For Beginners

teacher avatar Rahul Agarwal, Flutter Developer & Trainer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Introduction to Course

      0:41

    • 2.

      Lets Dive into Dart

      5:04

    • 3.

      Variables and DataType

      7:02

    • 4.

      String & String interpolation

      6:06

    • 5.

      Final & Const Keywords

      6:01

    • 6.

      Conditional Statements

      9:33

    • 7.

      Lists

      12:46

    • 8.

      Maps

      11:48

    • 9.

      Looping Statements

      14:31

    • 10.

      Break and Continue

      4:31

    • 11.

      Declaring Functions and Short hand Syntax

      18:37

    • 12.

      Types of Parameters in Function

      19:02

    • 13.

      What are Classes and Objects

      16:14

    • 14.

      Generic Type & Inheritance

      13:41

    • 15.

      Exception Handling using Try Catch

      6:48

    • 16.

      Static variables and methods

      10:52

    • 17.

      Ternary operator and Null safety

      19:24

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

126

Students

--

Project

About This Class

Learn Dart and become an expert with this interactive course. Dart is a clean, simple, class-based object-oriented language.

However, you can’t have a conversation about Dart without mentioning Flutter. Flutter is Google’s mobile UI framework used for crafting high-quality native interfaces on iOS and Android. Flutter applications are written using the Dart programming language, which has helped make Dart a beloved language by the developer community. Before you can start fluttering out applications using Flutter, you need to learn Dart. This course will help you learn the fundamentals of Dart, and get you started on your journey to learning Flutter. Start learning today.

The Course has been updated after the release of Flutter 2.0 which brought the concept of Null safety in dart.

In this course you'll learn:

  • Working with DartPad

  • Exploring the first Dart application

  • Built-in Data Types and variable declarations

  • Conditional Statements

  • Loops or Iterators

  • Functions and Methods

  • Object Oriented concepts

  • Inheritance

  • Constructors

  • Dart Collection: List and Map

  • Arguments and its types

  • Null Safety Concepts

  • Summary

Meet Your Teacher

Teacher Profile Image

Rahul Agarwal

Flutter Developer & Trainer

Teacher

Hello, I'm Rahul. I am skilled in building cross platform application using Flutter. I am freelance developer as well as conduct workshops to share my knowledge with the community.

See full profile

Level: Beginner

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction to Course: Hi, welcome to. But when the nurse corps for that programming to non-verbal, first we should know the fundamentals of Dart language at demand for developers is increasing day by day. And that is why we should make sure that we know all the required concepts. Before starting this course, I would like to introduce myself. I am, I am a developer as a conduct workshops well enough to medieval personal crazy and will linger community on Meetup. Always remember, programming is an art and we are dark. Just so get ready the code. And let's get started. 2. Lets Dive into Dart: Hi, welcome to dark programming section. Cross-platform development is a very hot topic nowadays, and we have few options in market to build applications. Among them, Florida has gained immense popularity within a short period of time. But before directly jumping into Flutter, we must know the fundamentals of that programming. Dart is developed by Google. And it's just like any other programming language such as C java script with basic concept, which we will discuss shortly. So without wasting any more time on the theoretical, let's start learning step-by-step. The first thing we have to do is to install dark. Dead easy start as the cave which you can install separately. But in this session we will be using the online dot bed because later on when we will be learning flutter and installing all the flooded tools, then that will be installed automatically. So we don't have to do it separately right now. And that is just an online tool to develop and write the codes. For that. You can just go to your browser and type dot pad. And see here it is. You write the code in the left-hand side. And the right-hand side, the output will be there. If I click on the Run button, you can see this hello123 for, this is a kind of for-loop which we will discuss later on. So if we say, what are the basics of Dart language? The very basic is the entry point, which is the main function. Here you can see this main function is the entry point of code, which simply means if we execute that code, whatever that is written inside this main function will be executed at first. If dotting our return here, it won't work until and unless it's a function, and we call it inside the main function. So to output anything, we used up print statement. Here you can see if I remove this and just like print, flutter is awesome. And run, then you can see it's printing. So simply, if you are coming from any PHP or any other programming language, you know, misprints statement is very common in most of the languages. And also strings, neat quotes, but integer don't. Which simply in place. If I'm writing print 2021, then it doesn't need any double quotes or single quotes. But if it's a string that is alphabets, then definitely it requires quotes. Now, we know what is the point, what is the print statement? And next thing we have to understand is that comments in any programming language comment will be there. It's like to understand what's going on in the functions. Comments are just for reference and don't get executed. What that means is, if I write here down, next statement will print out string and then run it. You won't see this statement in that console because it's a comment. Now, comments I usually used. So that in future, when you are looking back into the code, it's very easy to you for you to understand it and don't get confused later on. So this is the very basic, and I don't think so. It's that much of hectic. In the next session, we will learn more about what our variables and what are data types. 3. Variables and DataType: Hello. In this video, we will learn about what are variables and data types. If you are coming from an engineering background or any BC type degree, you might have heard this term stare. It's the very basic of any programming language. So what basically is a variable? Variables are used to store information to be referenced and manipulated later. That means if you have any mean, suppose flutter, then you just stored it in a variable. Like language. Language is equal to flutter. And whenever you want to output that flutter, you just use that language, word, keyword, you can say. Now, what are data types? There are some built-in datatypes. That is Numbers, Strings, Booleans, list, and map. List our arrays in PHP, it's called arrays, and here it's called list. The concept is the same. And also maps. Maps is just a key value pair, like dictionary in Python language, multidimensional array in PHP. So there is nothing new in Dart language, reading is just the same. It's just, you have to refresh your memory here. Now, the thing is how to declare a variable. This is a pattern. First is the data type, second is the variable name and gets an equal sign, which equals the value. Now this age has a delay of integer, a, 25 to 30, whatever. And this age has it. The datatype of war that is, which simply implies that we don't know what it will hold. It may have integer, it may have string. But here, if I tried to write something like Florida a string, it will show an error because the datatype is given integer. And remember, flutter or dark is a statically typed language. That means most of the time you will specify 51, a type variable or the function will hold. This is the main thing. You just, you don't, you just don't ever forget that. If we have a sign-in data type, then the variable must hold that value. Now, each and every datatype we will discuss step-by-step, one-by-one. But in the next video, Let's practice on latest numbers, which will be integer and double. And this string, I have this basic example. Here. We are using the example of the movie Avengers. If you haven't watched the movie, it's fine. But I guess most of us are Marvel fans. Though. You might have heard about this name, Iron Man, and let's bring out our dark and remove whatever it's in the main function and start from the very beginning. In the last session, we have heard about the comments which we will use now. Here, it's like declaring variables. Then now it's time to declare our first variable. The first thing we have to write, type, it will be int. Then the name of the variable. It will be scored, which will equal to 3000. So simply, we have completed our task of declaring a variable. Now, suppose this is an integer, but what happens if there is a decimal value? Suppose turkey 0.5 or whatever. If you have a Pi value and not in that case, the data type will be double. Double percentage is equal to 92.5. You just say you can add whatever you want. Then if you want to have any string, then it will let string hero is equal to Ironman. If you have any other hero of your own, you can just write it down. No issue. And when will we pan us? Okay, we have declared successfully our four variables here. Now it's time to print them. So just remember for printing, we have learned that we have to use the print statement. And this print statement will only print out value in that console. So when you are building a real third application, if you use this print, don't expect that the CUI or the screen of the mobile application will output dove value. Only the value is available for the debug are the developer usage. So if you want, you just print score. Then you can print percentage. Then then it's hero. And then print wheel and you run, you run the program. And I hope, yes, we got the output. It's like 3000. It's the integer percentage is 92.5, hero Ironman and then 10 us. So I guess it's clear with you the concept of variables and their types. And we have successfully understood numbers and string types. In the next video, we will discuss more about strings, which will help us understand that concept deeply. 4. String & String interpolation: In this session, we will know more about strings. Earlier, we have used a string data type, but in this video we will just know the definitions and concepts. So what is string? Strings are just collections of characters or you can say alphabets. We can declare a string with both single and double quotes. It's like String name is a call to Flutter. Here we are using single quotes. Here. You can use also double-quotes. But the problem arises when there is something like it's easy or something which has within the code. So you can say, if I have this war name is equal to its 11. Now, it will show it because you have single quotes within single quotes. To solve this issue, you have to either use backslash r, right? Single quotes within double-quotes to avoid any added. Here, backslash here, you have to just simply use this and the error will be gone. If I now run the program, you can see the output will be there. And if you want, you can just simply use remove the backslash and use double-quotes in the outside. Then also your program will run smoothly. So this this situation might happen while you are building an application that you have some thing like it's dares or whatever. We just have to remember that you cannot use single quotes within single quotes or double quotes within double-quotes. So we know how to declare a string. Now what is the string interpolation? This is also very simple. It's like a combination of variables and strings. Usually in any other programming language, we can combine variables and strings like this. That is why the name is called arrival. Print, my name is and then plus symbol and the variable name. This is also correct and dark, but not recommended. That prefers to write variables inside the double quotes by using dollar before the variable name will just show you. By doing it. Suppose the variable is Hero. I have to write. My hero is. And then Ironman. For that, I have to use this dollar sign and then that variable name. And if I run the program, see, my hero is Ironman. It's string interpolation. Earlier we would just printing out variables. But definitely in the real-world applications, you have to use something like welcome guests. Guests will be variable. And then if the user logs in, then that guest name will change to the user's username. So that is why the string interpolation is a very crucial topic. Now, within that poets, that is, we can output using this dollar symbol. But what if, if there is some kind of functions like addition or getting land? In that case, you have to use Donner and these curly braces. You can see the example here. And we'll also do it on our own. I'm just removing all this just for the simplicity. Like int length is equal to 20 and then bert is equal to 10. Now, if I want to do some kind of calculation with our variables, then I have to write some is dollar, then this parentheses, and inside that land. All right? Yep. Now if I run, it will simply sum is 30 C. But you cannot do like this. And this. If you try to do using only the dollar sign, it will just print it. Sum is 20 plus 30, but it doesn't do that calculation portion. So you have to remember this while building an application because there will be lot of times where you have to do some kind of functions. You might have to get the length of the array. In that case, this dollar and curly braces is used. If you want, you can just try some more example by creating like Japanese area. There is parameter, there is lot of mathematical calculations if you want, you can just practice on your own. That's it. This concept is done. This is the very basic concept of string. In the upcoming videos, we will learn some new keywords as well. 5. Final & Const Keywords: Today we will learn about what our constants in that language. So when we hear the word constants, the first thing that came to our mind is that the value won't be changed. That the value cannot be changed. It's a constant value. So we didn't the constants, there are two keywords. First is finite, and the second is that constant. Now let's start with that const keyword definition is very simple. Const is use if the value is known at compile time. We just forget this term of terms in simple words. While development of the application, we hard coded value, that is constant int marks is equal to 90 marks. Let's try our own. There will be const int marks is equal to 90. And if you print, can you sprint marks. And I will remove the data above print statement. Now you can say it's 90, It's tin cans. That is, if we try to change the value later on, like 58 is Marx is equal to 50. Get will be an error. Chance to values cannot be assigned. That is, if the value is fixed, we cannot change it later on program. This is the use of const keyword. Now you might be thinking, okay, Const a, I get it, but what is this final keyword? It's little bit tricky. It's like suppose we don't know that value while writing code, but the value will be calculated. Our fetch from database at Runtime. Runtime means whether the application is operand. And after that, after the value has been calculated, we don't want the value to be changed after being fetched. So it's like some database. There will be the user's age. It will be final, each keyword. But once it's fetched from the database, after that, the user cannot change that value. So here you cannot try and write it directly. If you just write final string name is equal to flutter. Then also it will work. Normally. It won't show any error here because in the end it's a constant. But you will understand more of this concept later on while building area level application. But here in the example, you can just see the value of pi, that is 3.14 is a constant. In that we will use the const keyword. But while data is available, and if we assign it to date, time dot now, this will be a final because suppose the app appends at 10 o'clock. At that time, that date will be ten o'clock. It will be fetched once and after. That date won't be change, but that date value hasn't been written. Fleet. Then in that code, we can do it with a very basic example. Can just say, write int x is equal to 1, y is equal to 2. Final a is equal to x. Then for int a. And here I will let const b is equal to y. Print B. Let's see. It will show an adder because we cannot just write something, which is not only did they are here, if we are using a const here, the value has to be returned like five. But in the above, final, a is equal to x. It's not showing any error. Because the final is like if we run the application and the value gets inside that final variable, It's okay for it. After that I cannot change it. Like is equal to 26. This I cannot do because it's a type of constant. So you will understood, you can understand this concept here in a very basic manner. If it's a const keyword, then we have to write the value. And if it's a final keyword, tender variable might hold something which will be assigned later on. That's it. 6. Conditional Statements: In this session, we will know about conditional statements. Conditional statements will be there in any programming language, PHP, Python, Java, C, C plus plus serve to whatever. The concept of conditional statement will always be there. So what are conditional statements? It's like there will be one condition. If that's true, then do something else. Don't do something. The first conditional statement is if else can see here, offense, if that condition is true, then run the code, RS, run other code. It's very straightforward. And the second one is if, else, if that means if you have multiple conditions, suppose if age is greater than 18, then they are allowed to drive. If then, else, if, else if age is greater than 21, then they are allowed to go to clubs and all. And simply, in the end, else you could just write Ps mentioned your age. It's basically some kind of conditions in your application. And trust me, when you are building any, any real-world application, there will be lot of conditions. If you see Facebook, you can just see if the user has logged in. Then show the homepage else, show dialogue in breach. That's a very good example, I will say. Now, there are some operators as well, which we use frequently with if else statements, that is end are our. Two conditions can be used, can be joined using and R. And both have their own meaning. And operator means. Both. Conditions specified must be true. That is, if age is greater than 18 and person is from Tell him. In that case, there are two conditions which both of them should be satisfied to run that code. And when it comes to the operator, it's just like if that person either is greater than 18, are from Delhi, if any one of them is true, then we can the system can execute the code. You can just sketch out the basic information from her because right now, we will start with an example. Let's do it. Again. I am here using that injures scenario so that it will be easy to understand. Let's remove the previous codes and let's start it. Here first. I will be using comments when writing declaring variables below. Now, we have used that const keyword earlier. Here I will write const int stones is equal to 6. For your use, I can just write comment like using const so that number of stones cannot be changed. Simple. Dense stream, string. Hero is equal to Iron Man. And string we learn is equal to tan us. Down. That new data type here will be Boolean. Boolean is what you can just say, true or false. Boolean is nothing but that to value, either it will be true or false. So we have this Boolean, hero, when is it equal to true? And again, Boolean. We learn when is equal to false. So we have successfully declared all the variables needed, the five variables here. Now we will use conditional statements. If our first condition will be if stones less than six, print. You have not collected infinity stones. One condition instead, second condition, if r is equal to 6, that means stones are six. And then when is equal to 2. That means the villain wins here in this case, we will print by using string interpolation. We learn has again string interpolation, six infinity stones. Now we have written two conditions here. That third we can say because if else you can have multiple conditions, there is no boundary. Again, if stones is equal to six and heroin is equal to true. In that case, you just simply plink. Hero reaches the Iron Man as six, which is the stones, infinity stones. And finally, in the else statement, you can write hero. And we don't care about stones. Simple. Now, with your mind, just think, what will be output here stones is 0, 6, and 0 when is true? So first one will be false, second one will be false, third one. So the output will be added. Man has our last six infinity stones. But if I simply make this false as well, then it will last. Else will be executed because not even one of the conditions are satisfied. And I'm this, I'm just reminding it again. Since tones are constant, you cannot change the stones value. Here. Like this. It will show an adder. So I hope you have understood clearly what our conditional statements and if else is very self-explanatory. Because if one condition is true, then print it. Print the other thing. So that's it for all today. See you in the next video. 7. Lists: Until now we have discussed few of the data types such as strings, doubles, booleans as well. But now it's time to discuss list. This is a very important topic because while building an application, we will be using distinct type it in most of the time. Now what is a list? A list is simply an ordered group of any data type. It is commonly known as ADH is in other languages, if you are coming from PHP or anything or any other programming language you might have heard about arrays. So it simply means earlier when we were declaring any variable, it was whole link, one value. That is, suppose this Wilson was holding only tennis. But what if we wanted variable which will contain multiple information of the user? Suppose the name, contact number, age, everything in one way, but in that case, we will be using list. It is very convenient to store and access the data in that way. Now, each element in the list is defined by a unique number called that index. It's very simple. Suppose if you want to access a data from the variable, you just have to remember what index it is in. Obviously, to access anything, we must have some ID. Here. Id, the ID is the index and it starts from 0. Let's start programming. I guess TOD you have understood, I will remove the previous thing. To declare a list. We have to mention that datatype At first list. Then simply I will just write marks and the square brackets. So we have successfully declared enlist. And you can just see in the above the string boolean odd integer as well. But this time it's a new data type list. And when I was saying about the index positions, what I mean was, suppose in the list of marks, there are multiple values like this. Okay? There are four values in this variable. And now this 90 is in the 0 position, it is in the one position, sixties in that two, and 30 is in the tree. So this is the index. Simply you can just say suppose if I want to access this 90, I simply have to write print marks and that index position 0. Now let's run the program. See 90. You have this value. Now suppose if you want tidy, what index you have to write? It will be three. Then, yeah, then it's 30 is printed. Now, that thing is, suppose we have an empty list of age, OK, and V1 to assign a value into a new way. That is, it might be, it is empty. But later on we want to assign. In that case, you cannot just directly write age in the 0 position, give to date. This will show an adder when we are printing age list. Let's see, try it out. See uncaught, add a range error, which means this is not the correct way to assign their value. But if you want to change stuff value which is already been assigned, that is Enda marks. In that 0 position, you want to write 10. And then print marks. List. Let's see what happens. See, 90 has changed to ten, which simply implies you can change the already existing value with this method, but you cannot assign. Now, you might ask me then how we will assign a value because Marx's already pre-written. But when we are building an application, all those data will be in the real time. In that case, I just have to write H dot and then add. This is a function. This is the, you can say operations which a list excepts age, dot add 25, and then I will print out Age. See, 25 is there. And now it's not showing any error because this is the correct way of adding a value inside the list. Again, if I write H dot, add 13, and print it, then it will be 25 and tidy C. So it's a very easy concept and very important because list is the only way when we are fetching a lot of, suppose in a, in an application like Facebook, there will be a lot of users. So all let users might be stored in a list. If you see this slide, I have written that the index starts from 0 and extends up to n minus 1, where n is the total number of elements in the list. What I mean by that is the index here. It starts from 0 and ends at three, which is the total number of elements in the list minus 1, that is 1, 2, 3, 4, 4 minus 1, 3. Since it starts with 0, that ending will be always the total number of elements minus one. It's a very important concept of any programming language. Now, we have done this portion where we cannot assign value to an empty list. We have also done dispersion as well. We're already assigned value can be changed like this. Now, there are few operations which can be done in any list. That add portion is done. Now, if you want to remove any element, then it's very easy. It's like list, name, which is Marx dot remove. And what data you want to remove. I want to remove supposed 25. And then I will print it. It should unleash, displayed 30. I guess I did a small mistake. It's like when we are removing, we might have to use remove at so that we assign the index. Suppose here I want to remove 0. Okay? Okay, is have us removing from the marks and printing age divide will show they're removed. Let's do it again. In Marx I went to remove 90 and then print marks here. Let's check out these output. C, 90 is one. So in this way, we can remove the element if we know the value of the element. But suppose we don't know that value and we just know the index that is marks, dot, remove, add. And here I will give index as suppose one and commented before remove line. Now the 80 will be removed. See 10, 60, 30, but a t is not there. So remove and remove at our two operations which are very important. Because definitely when we have inserted any value, if the user wants to delete it, he should have that capability. Are that feature you can see. Now, the final thing is the length of the list. That is, if we want to get the length, we just saw, right? Print marks dot length. And I will just stop removing elements. And now let's say I think it will show for which I was discussing earlier, that is, this is the n value and the final element always is the length minus one. And if you want to print something like this with concatenation, you can do like this. The length of the list is then dollar. And just remember from the last session, if we want to do any operation, then we have to do dollar and then curly braces. And then it marks dot length. I will run it again and see the length of the list is four. So I just want to give a recap of concatenation because I don't want you to forget the previous concepts as well. So okay, that's all for this video. We will meet again in the next video. Thank you. 8. Maps: So now it's time to learn about the next data type, which is Tom map. Map is also a very important datatype. When we are building a flood application. Mostly you will use list. Our map are, you will use map inside list. Right now if you are getting confuse, no issue. In the later videos, you will understand what I meant to say. So what is a map? A map is a simple key value pair, which means earlier when it was a list, you can just see it was their value. But it doesn't have any name. You can just say it had that index in them from which we can call them, but it didn't have a name. So when that data is very long or when data is a lot of data, It's very difficult to remember the index of the value. In that case, maps are very handy. So let's see what it means. That key will be of string type, but the values in a map may be of any type that is key will be supposed name. Then the value can be string, that is Rahul flutter or whatever. But also dot key name can have 22 or 23 whatever numeric values. So it's not mandatory to use only string as its value. To declare this map, we can use the map constructed that is this one. Are, you need to enclose the key value pairs with an echo lubricates like this. Let's start by creating our first map. Again, I will remove this data and start with a clean slit. Now, when you're using a Mac constructor, you can just write var fruits is equal to map. And after that, their fruits. You can write apple as that key. Just remember as the key and its value will be red. Now, if I print fruits variable and here var, or also you can use map as a datatype. There won't be any error. See, this? Apple and red. Apple is that key, and red is the value. So most of the time we don't need this E, we need this value of red to print that. You simply have to write Map variable limb, and then dot py, which is Apple. Now run your program. And in the output you will see Red Sea. This is how we do it. This is how map is being used. Now, again, if you want to add another value of banana with a value of yellow. And again, first, print the whole map so that you can see how it is being displayed. It's like first key is Apple, then the value is red and commas second key is banana, and value is yellow. Now you might ask me, let's print out yellow value. In that case, first, I have to write them map name. Then that key, which is not a more valid example, you can say, will be some users map and that we will do using map literally earlier, this is done using map constructor. Now, we will declare a map using curly braces directly, which means. I have a map of user. Then here, first key will be named Bill Gates. Second, you can say age. I don't know this exact age, but suppose example 88 and tired, Where will be founder? And it will again be a string, Microsoft. So here you can see this is how we declare a map. This is also a type of delayed type which will hold multiple values, like just like list. So now if I want, I will just write print user and then I will just comment the above lines. See named Bill Gates founder, Microsoft. Also. In the same way if you want, like print. And we'll show you how to print a very new, not new. It's like for missing tense for a founder than for the Microsoft evidence right? Under is. Now again, I relate user and then name. Here I'm using concatenation. And you will learn how to fetch data value from a map. I guess there is some added. Again, must end with this. Yeah, I know what I did. Here. It's a very basic mistake. Nothing much. In programming, you are used to this kind of silly mistakes. Now, you get the output funder of Microsoft is baguettes. So this is the wave, how you will output that data in your real application. It's very important thing to learn. And also you can also print the length of the map, as we've done before in the list, it will be three. That is, there are three values. See three values. Other operations includes suppose user dot. You will see if I just write user print keys. It will show all that key is that it is name, age, founder. So that if you forgot Also, then you can just check it out. And suppose from that keys, you wonder values. That is, you don't remember any of the keys, but you want to fetch all the values, then you have to use a function or operation like user dot. For each debt is it will go through the map with this key value. And you can just write print. If you want value, you can just print that value. And we'll again commend down the above Ting and print and run it. And now you will see Bill Gates AT and Microsoft. This is how you look through the map. And you don't have to take this much stress. In the upcoming sessions. We'll be talking deeply about loops. But right now, our concern was map. And we have learned a lot, the final operation, which is important, obviously there are a lot of operation you can see, see. But the final if you can say it's like remove. If you want to remove a key, you can just write remove, then that key, key name will be named. And after that, if you drink, then you won't see Bill Gates here. See Bill Gates was removed from the map. So that's it. This is the basic concepts. I hope you just understood the basic thing because to master down least our map, you have to practice it while building a real-world application. Thank you. 9. Looping Statements: In this session, we will be talking about loops and what are looping. So if you are coming from any other programming language, I guess you might have heard this for, FOR loop or for a do-while loops. And because in engineering or any basic programming, this concept will be there. So loops are used to output multiple number of times. Data can be. If we have to write, suppose our name a 100 times, we won't just print, print, clutter print Florida when flatter. It will take a lot of time. In that case, we will, we can use loops. And in the end, I will definitely tell you while building a real world application where loops are being used. So loops out of four types, 44 in y to y. Let's start understanding it one by one. So what is a for loop? The far loop executes a block of code for a specific number of time, which we mentioned in that loop. So the syntax is like this. We use for then brackets. There is parenthesis. Inside that there will be three data. First will be initialisation condition and what should be done. You might get confused right now. Let's do it practically. I will remove all this thing. Let's start it. Loops. First will be for loop. So suppose I have this for loop syntax. First is initialization, that is int variable I is equal to 0. Then the condition I less than three. And then what should be done next? After this code of block will be executed. Like if I write print. So if I click Run, This is how it will done. Far I is equal to 0. That is, I will be 0. Then it will check the condition. If I value is less than three. If it's true, then it will go in set and execute this block of code. After the execution of this block of code, then it will go to this step, that is I plus plus, which implies I will become from 0 to one. Let's run it. See 012. It doesn't go forward. That is after 23 because there is this condition. So this is a very basic thing. But most of the time we will be using loops while dealing with lists are mapped. So I will write list. Marx is equal to again 50, 30, 20, 10. Then I will write for int I is equal to 0. I will be less than the length of that list, which will be four. And I plus, plus. And now if phi one to print out, then I will just write that list name and the index, which will start from 0 because we have mentioned it here. So if you want, you can just pause and understand it again, because int I is 0, it will check if I is less than the length, which is four. If yes, then it will print that value in the list of that index. First will be 0, that is 50. After that, it will do this step, I plus plus one. And then again, the same thing will happen. Let's see the output. You can see the output 1532, indeed 10. So the loop is very powerful. And while building a real-world application, you will be using loops all the time. Because the data which will be coming from the database will be in the form of an array. List. So you have understood this for loop. Now done Next loop is for NLU. So you might be thinking why this for NLU, the for-in loop is used to loop through and list out a map. It is being mostly, it is being used most of the time just because this looping through data list is so common. So there is this specific kind of loop where we don't have to mention like that initialization, this tab panel, because it's a waste of time if we already know what we have to do. So I will comment the above four. And here, let's write this. And far way of writing. Loop goes like what? Mark, that. This is a simple variable in marks. And then print mark. See, the output is same, but the code looks so much cleaner than above because it's simply, it's doing what? It is. Assigning this mark variable to the first element, second element, and then printing it automatically. And this for loop inbuilt knows that it should loop two dot length of the list, it should not exceed. So it's a very common practice of using for-loop in that real-world application. I guess you have understood it this far in, can be used in Maps as well. You have seen list, but let's try map. Var. User is equal to c0 will be around age will be suppose 25. And then second we'll take, this is another name and age will be saved 30. Now, if you want to loop to this map, is simply will write far. This is the day of any variable name in Mark's dot entries. So this is something you have to remember. Let's see, I guess yes, so many operations you can do. Let's print and see what it outputs. Data dot. If I just write data, let's see. It shows an error or anything. Sorry, I have to write user. This was again silly mistake. So this user, if we are using a map, then you have to write entries. This you have to remember by heart, because map is a different type of datatype. And then you can just write data dot key and print if you want value then data dot value. And let's sit on it. See Rahul 25, tick tock. So just imagine this user right now, it's containing only two data. But if you have an application like Facebook and get our cohorts or lax and whatever number of data, it's impossible for you to write everyone by dead keys. In that case, we will be using looping. Now, more of the looping you will understand while we're building a flutter application right now, you just understand the concept. Two loops are being done. Then next one is the while loop. While loop also does the same job. It is not like very different. It also loops through the elements. We mostly use while loop when we do know how many times the loop will actually execute. Here in example, we know the limit, that is while number less than this. But suppose a music is being played and until, and unless the user presses the stop button, it should continue playing. This is a good example. So let's do it through the while loop as well. I will comment it. Then. I will just write int number is equal to 0, y. Y is the number less than 10. Print number. And number plus, plus that is implemented. It's nothing new. It's same as the for-loop. See, the way of writing is different. For loop is being written like this and vile is like this. So the final loop is that do while, do while loop is different from the while loop because in the wild loop, first condition was tagged. And then after the code of block was executed. But first the code is executed at least once, and then the condition will be checked. Let's try it. With the same example. In this number is 0. So we will just say do print number, but that condition will be number greater than one. So just imagine here that condition is false. So if we were using this while loop, it shouldn't print. But since we are using do while, you check the output, see 0. It is being printed once. If I write here number plus, plus as well, then also the condition is false, but this code of block will be executed. So do-while is not being use much MATLAB. It's like I haven't used do-while, while building my applications. Most of the time we are dealing with for loop. So it's up to you which type of loop you want to use in your application. So in the next video, we will learn small two keywords as well which are being used while we are using loops and Q. 10. Break and Continue: This will be a very short session where we will discuss what our break and continue statement, break and continue statements are used with loops, any kind of loops. And what it does, we will just see because we avoid break only, you can understand that it terminates that. Look. Let's try it with the example. And when this, remove this and this right break statement. If we have a for loop, for var I is equal to 0, I less than five. I plus, plus. I hope you have understood this loop because last chapter we have already discussed this. Here. I can write print I, and you will definitely see doubt put as same from 0 to four. But what if I will have a condition here? Like if I is equal to then break. This will simply mean that if the number goes to two, it should terminate and then execute that code below. Let's run it and see it will be only 01. After that, the process is being terminated and the code will run down below. But when it comes to continue statement, continue will only skip debt would in that loop, but it will not terminate the whole board. Suppose I have here print, flutter. First, it will go 01, then it terminates and execute that code. But if I write down here, Continue. And all that code will be C, Just, I will be using continuum and then run it. See, there is a lot of different than brick because only when it was two, it does code was terminated. But it doesn't cause out of this for loop. It just check the condition again and sprinter rest of the code. And then only it will go and execute all the codes below. So this is a very basic but important concept because Hume, we'll have to use continue R4 far statement in your application whenever required. So I hope I have cleared your doubt. You, if you want, you can just try it again with some more examples. If you want, you can just write user list, then loop through it, and then try using break our if-else. It's up to you because when we are learning any programming language, it's better if we practice and try to address as well so that it will be beneficial for us for the future. So that's it for this video. 11. Declaring Functions and Short hand Syntax: Welcome back. In this session, we will be talking about a very important topic. So if you have any interest in programming, you might have come to the word function. Functions will be dear. Either you are working in PHP C, whatever, you have to understand the concept of functions. So what is a function? Function is just a collection of code. Are statements grouped together to perform a task. So when we are writing codes here, suppose this is just a really basic code, debt, so we can write it in a, in the same file. But what if there will be a 100 lines of code or a 100 functions to execute on a 100, the task to execute. In that case, we have to make use of functions so that we will declare that function somewhere else and call it here in our call it in multiple times wherever we want. So let's start. I will remove and clean everything until we like functions. So here you can see the syntax of a basic function. It consist of return type, optional, but it's recommended. Return type means what the function will return. And the second is function name. So it's just a kind of a variable name you can say, because our vastly to call a function, you have to give it a name. And that third thing is parameter arguments. That is what value we are sending to the function while we are calling it. So right now you might get confused, but no need to panic. We will understand it slowly step-by-step. And when I was saying and then type, sometimes the function may not return anything. In that case, we use void as the return type. So if you heard this vote, you might think, wait, I have seen it somewhere. So if you just go to duck code here, this is also a function that is the main function with the return type of void. So it's very weird that from the very early, around the very beginning, we were working with functions, but we didn't know it because this is the entry point. That's why we didn't discuss it earlier. By right now, you can see it's the same syntax that is return type, function name, and then parentheses and curly braces. This is how we declare the function. Now, the TOD is done. Let's write that off writing a function because there are different ways for different purposes. The first way is function without passing arguments. That means we are not passing any arguments towards the function and arguments where this values. Let's try it. Ourself. And we'll just write first function without fussing argument. And return type that this function is not returning anything. So I will declare it like void. Let's do some mathematical thing, fine, parameter. And then in the function, we can have variables, some executable codes, whatever we want. So I will just first declare a variable of integer for. Then second will be that of an desert. To. Then now let's do the calculation that is bad emitter will be a variable which will be holding this calculation two into L plus B. That is length plus bread. Okay? And then we will just print here the perimeter is and then concatenation. Okay? So here we have successfully declared a function. Now I told you, if we have a function, we have to call it. So how we will call it will just simply write fine parameter that is the function name and parenthesis, That's it. And now let's run the program. See, that parameter is 12, that is, four plus two is 66 into two is 12. So this is the first way of writing a function which doesn't have any return type and which is not getting any argument. That is deaf values are being returned inside the function. Okay, I hope you have understood till now, because now we are going to that next way of writing a function, which is function with arguments. As the name suggests. Here, we will be passing the argument when we are calling the function. So let's suppose here for declaring the parameters, I will write first data type of the parameter that is int length, and then second will be int bread. Now, if we are passing the value, then we don't have to declare the value inside the function. So I will remove it from here. Now its declaration part is done. But if we are calling a function, then here it's showing this error because we can just seen the edit to positional arguments expected that is, we have to pass the value to first I will just pass five and then second also five, that this land and bread. Now let's see again the output. See that parameter is 20. So what it will be, it will be funtion with passing argument. It's very simple. But I hope you have understood because this is a very core concept of the programming. Without this, you won't be able to understand further on. So I will suggest you if you have any doubts, you just also research on your own and tried to go deeper in side the concept. Now let's move on to the third, which is function with argument and the return type. So simply, we will just write set third way function with argument and the return type. So as the name itself suggests, that it will have argument like this and we will have a return type. So now the return-type won't be here, void, it will be int. Now you can see the adder dub body might be complete normally, but it's returning none because it's not returning any value. So what we have to do, we wouldn't print it inside the function. We will just say return the perimeter value c, that add is gone. So here we will have a return type of integer since both are integer and after calculation it becomes an integer. That's it. Now, if we are returning give value means, we might have to catch it somewhere. So here I will just write int. Result is a call to find pedometer. Now the result variable will consist of that calculated value sent by Duff function. So now, if we want, we can simply print like the phi dot result is. Then here. Now we have to write result parameter variable. Because we are storing it by this name. And also, if you want, you can do some more calculations further on, like int. Final total is equal to reason a result. Plus you can just write 200. And then here again print final result. After. So, after adding is, then find. So 10 K. It's showing some matter. And that's okay. Final total, sorry. Okay, now let's run the program. It should be first will be 5 plus 5, 10, 20, and then second will be obviously plus 100, 120. So we do this return type normally so that we can have some more calculations afterwards. It's like after when a user, when we try to get the age of a user, after getting that age, we might do some calculations. Let's, let's see. Suppose here it says int user age. Okay? And simply here we will just write return 20. Suppose. Now, what if I want to first int get user age, reducer age. And after getting the user age, we will do some calculations like if get user age is less than 18, print, he cannot drive. Else. Print. Allowed to drive a car. Now let's comment this and now let's run. And I hope you know what the result will be. It will read. Else because we are getting to in t When we are calling the function. And then from the if else statement, which we've already learned, we see if the user is legally allowed to drive a car or not. So this is a very basic use of whistling when we're building the complete application, we will have some more advanced usage of these functions. Now, the final, another way of writing a function, you can just say it's shorthand syntax, our fat arrow. Which means if our function body contains only one line of code, then we can use this arrow, arrow and this kind of arrow symbol. You can just say an, a coil and greater than to declare the function and make it look sharp. So it's just a way to clean our code. And also in the notes section, you can read in fat arrow notation, we don't use the curly braces and also don't use return key word. So data, there is a lot to digest. Again. Here let's try with this int fat arrow syntax. Here we have, we're just returning or you can have we have just one line of code. So first thing, it was told that we have to remove the curly braces. Okay, we removed it. And second, we don't have this return statement. Okay? And instead of that, we will have this arrow. See, it is looking so cool and so clean. And now again, I will just change that value to 17. And let's see. What is output. See, he cannot drive. Which simply means that the function is doing the same as before. But with this shorthand syntax, it's looking cleaner and it's easier to read. Debt is just returned 17 and there is this return type as well, which is an integer. And if you want here as well, you can do these changes. First. I will remove the curly braces. Then I will remove these return or return and simply, Yeah, I will write arrow. And this one line of code that is, after calculating, it will directly return to whatever it's calling. I will comment down and do it this again. And I hope the result will be same as before. See that result is 20 after final result, after adding is 120. So the earlier, it was looking very messy, but with the shorthand syntax, it's getting better. So I hope you have understood the basics of function. In the next video, we will go more deeper into parameters and its type. 12. Types of Parameters in Function: Now it's time to get deeper into parameters and it types. So earlier we have learned how to declare a function and how it accepts a parameter. But there are different ways to accept a parameter. In that diagram, you can see parameters are of two types, optional and required. The name only, you can understand it. If it's required, then you have to pass the argument. It will show an adder. And when it's optional, then data also treat types of optional that is partitional, named and default. So we will understand each and every one step-by-step. So let's get started. First, we will understand what are the required parameters. Let's bring our code editor and create a function name, print name. And suppose it accepts arguments like string name1, string name2, string name tree. Okay? And I will just print out the names like name1 and Name 2 and 3. Okay. We have our fund generally. Now it's time to call it like print name. But if we directly call it like this, it will show an adder because it's a required parameter type, which means we have to send a value. I will just send Hulk, Iron Man. And it's by demand. Let's see the output. Okay, you can see all those up printing. So it's really basic and we have done this earlier as well. But you have to understand what it is called and it is called a required parameter type. Now, the second type is optional. And within optional, we will be understanding what is a partitional optional parameter. So to make a parameter optional vi, use this brackets, square brackets and polish null means this hulk will be in the first position, that is string 1. This Iron Man will be in the second position that is name too, because this is the order how it's silly. Turn here, see if I change the order like Spider-Man here. And I didn't mean here. So this, the output will change, will be changed because it is positionally decided which one is rare. Now? Now, if I want to make this name tree optional, it is, I don't want it. If it's not send, then also it's fine. Like this. We have to use this square bracket. But they're issuing an ad because it's written. It's showing that the parameter name contact with a value of null because of its type and its type is string. So in the latest version, Dart has introduced something called null safety, which simply means if any variable, variable, our function can return a value which can be null. In that case, in that case, you have to declare that data type as nullable. Which can be done with that expression question mark. Which simply means if I have this string and I just insert a question mark here, that means this value, this variable can contain a null as well. Which in our case is true. And now if I run the program, see Hulk and Spider-Man and null because we haven't passed a value. So here, this concept is very, also very important because when you are asking a value from the user, you, many of the frills may be optional. Suppose what interests are, what age you are, or how much money you on the user may or may not want to fill those farms. So in that case, you can have those variables as optional. And just remember, this null safety is recently introduced. So if you're watching any video to do real R, which is suppose six months or one year back. So dare this question mark is not being introduced. So you might get some errors. And here down you can see that null safeties on because it's default into Flutter Framework. So I, this is optional parameter type. Now I have, I have explained everything here. Now done next is named parameter. Now this is little interesting. Layer. We were just using partitional parameters because there are very few arguments which we were passing. But suppose we have lot of parameters that it will be very difficult to remember their petitions. That is, in the one position, its name in the second position, its age, in that third position, its city. Not always feasible to remember all those. So in that case we use name parameters, and here we will be using curly braces. We learned to use square braces, but now we will use curly braces. And simply, I will create a new function which will be named fat. Third, okay, I will write int find volume. And then in that parameter, I will simply write curly braces and then int length, int, read, and write Clint and will not print here, I will just return length into bread. And if I want height as well because it's the volume, I will declare an adder parameter of height. Now you might be seeing some areas. I will explain you. What's that? Because here the parameter becomes optional by default. So you have to use null safety within curly braces. So in name parameters, the values becomes option and that is, it can be null. We have to use null safety, which is very simple as simply use question mark, question mark, question mark. But if you are using the quotient mark here, it will show some address as well. Because we cannot do calculation. We cannot do this kind of calculations here if the value is null. So in that case, I will just check. Let's try and check if length not equal, length equal to null and bread equal to null and equal to null. Then return. Again. Is this kind of situations you will encounter a lot while programming. So for this solution, you can do one thing. Either. You can just make it optional. But sorry, make it a name. But with required keyword debt is this function has to return a value because it's a very simple concept. If we're doing any kind of mathematical calculation, the value has to be provided. So that required thing, make sure the value is being sent. Now, if I call the function like find volume, I cannot just pass value like this. Because it's a name parameter. It has its own name, which we can see here. Height can be five, comma five, and length can be five. So if you notice here it, since it's not positional, I can call the value at any position because first I have called height, but there it was land. Then I call bread. It was red, but last it was high. But I call length because it's a name parameter and we don't have to remember the positions of the arguments. And simply I will print volume, value, sorry, volume, spelling, volume. And we'll run and see 125. So since it's a named argument, d or we can call it by this names. And it's much more easier because it can be name, age, salary. We don't have to remember anything. Now it's time to use the final, buy them, whatever it is that default parameter. Now, in the same case, I'll just remove all this and I will write default parameter. In the same case. If it was not required, if it was like this. In that case, default wins. If the value is not being sent, then we will have this value. Instead. It's like length will be one. Height will read this, and bread will be four. So here, if I supposed forget to send land, then also it will, the length will be one. That is, let's make it too. So the calculation you will see clearly two into 51010 into 550. See, I haven't sent the parameter land, but it was, since it was default there. And you can program, it doesn't get crashed. A good example is white profile. And also remember, we can use positional and name parameter both at the same time. Like string, host is equal to guest here will be the default parameter. And I will just simply print. Workshop is conducted by host. Okay? Now, if I call the function, now, please concentrate because the first parameter is a position. So I have, I cannot just say work, shop and this, No, it will show an adder to support additional I have to write flutter. And second one is named. So host will be suppose Google. And now let's run the program. See flattered is conducted by Google. But suppose, if I forget or don't want to give the value of parameter of host, then it will not show any editor. And it will simply become flooded is conducted by guest. So if you see an example of Facebook, you will understand there will be welcome guests, and after you login, there will be welcome your username. This is a very basic example of using default parameters. So I hope you have understood that concept deeply. This is all what is required for functions concept. So in the next video, we will learn some more concepts of, oops, that is classes and object. See you in the next video. 13. What are Classes and Objects: Welcome back. In this session we will talk about object-oriented programming. So this concept is available in other programming language as welded is Java, PHP by 10. So it includes how we see our quote or how we organize our code. Object means whatever object is there in the real life. If you see a car, our students, our book, you can see these are all can be combined in their own respective classes. Let's see. First what I meant. I will remove everything. And then classes and objects. This is a topic we will be covering today. So suppose there is a data string name is equal to B delegates. I'm just inspired by them. Then string college, you can see how World War I guess C a string, okay? Int marks. He doesn't make sense to give marks to Bill Gates. Supposed to know. This is that data of wants to rent dense. That, that is why it is possible to just write it down like this and bring it in, print it one by one. But what if there are many sprints? So obviously you want just sit and write string. Name two is equal to elon Musk. Like this, because it doesn't make any sense. Here. If you see that these are all added our name, college marks can be combined into a class called Student. And then we can mention these variables are intrinsic properties because when we are talking about object oriented programming, variables are known as properties and functions are known as methods. Both are same just when it goes inside that class. If their name has changed, nothing, when it doesn't make any sense to me why we call it like that. But you, you will understand. You don't have to think that much. So let's start. What is it? Class? A class is a blueprint. Our featured common to all its objects. Object, we will understand in a way. But you could, you can just from the definition only can understand It's the features common in Alda data. So we just make it a separate class. Example is student class. All students will have their ID and name. All students perform functions like study and play. So we can make it a class. In class. Functions, in class, sorry, functions are called methods and variables are called properties. As I discussed earlier, that these are just interchangeable, but they are called like this. Let's now create a new class of first-class student ID, string name. Then 30. Suppose turning and just play. Brent, playing. So now the thing is this class has to be outside our main function. And here it is showing an error because we haven't mentioned that this variable will be null or not. So since we haven't. Assign any value will make it null safety because if we would have a sign like this, then it's a different situation. But right now there is no value being assigned. So you can just say if I have mentioned this class here until, and unless an object has been created, it doesn't store any memory. So you might be asking, I have used the word object multiple times. Then, what exactly an object means? An object is something that we'll assign value, our access, all variables and methods defined in a class that these variables in functions, you can say in our example the variables are ID and name, and function is 30, and play. So we have defined that, those properties, but obviously in our application we have to do something to make use of the property and dare the concept of objects come into play. So we, we had this during class, but now what if we want to enter is to be it, then we have to make an instance of the class. Let's try it. We will just write one student, one is equal to student and then parentheses, it is call like this. That is the object creation, you can say. Then you will see we can just stretch to rent one dot. And then we can access everything. First, I will assign an ID like one. And then student one dot name is equal to Bill Gates. Now, if I print student one dot name, and if I printed above, that is when we haven't assigned. Let's see the output. See first it's null because we haven't assigned the value. But then after you can see if we wrote like this dot and then access that property, then we can assign that property of value. And if you want to access the function, you can directly say student 130. See. Now it will show studying and I will just remove this. Okay? This is one object. That is, this is one. Now if you want, you can just create multiple strings like this to rent to object. Again, object. And then student to dot ID is equal to two. So now you might be thinking or you can just see this assignment of value is little bit not clean, you can say because we have to do dot this.name. We tend to write it again and again. So to tackle or to solve that thing, the concept of constructors alive. So you know, again you will ask, what are constructors? This is again, a concept of object oriented programming. Constructors are just like functions within a class, which will run before executing any other code in that class. Irrespective of position, I will explained as any other method has to be called. But even if we don't call the constructor, it will automatically get executed. It's who might be thinking what's going on. What is exactly a constructor? First, I will simply teach you how to define a constructor. A constructor is declared by writing the class name. Parenthesis, the class name is student, and this parenthesis is like this. Okay? So this is a constructor. And when I mentioned that it will be executed first irrespective of its positionality, If I write to the disk constructed at the last also now, then else, first of fall when we create an object, this will be called and you can just see these and these are basically save money by their looks or you can buy how it's written. They are both the same. And the second feature African structure is that a constructor is like a function I, as I said, but it doesn't have any leg this return type. They don't return anything. It can just execute. Within this class of what we do most of the time is we assign a value. And first of I will just show a constructor and just write print. This is a constructor. And sorry for the semicolon. And I will again just create one class. And now you see the code is written from top to bottom. But first of all, this will be printed from there only you can understand that the constructed is executed at the very beginning. See this is a constructed then Bill Gates and then studying. So this is the, this is the meaning of a constructor. Just remember it's the same name as the class name and they don't return anything. You, now you will ask me. So k, I have understood the constructor, but what is the use of it? So mostly we have before the US, we must know what is a parameterized constructor. Just like in a normal function, how we send parameter or how we send arguments. In the same manner. We have to send an parameter to a disk constructor. And then that parameter will be assigned. That is, the value will be assigned to the variable present in that class. Simply, here, we were assigning it like this, but now onwards, we will just send it. And then it will be assigned like the, like, Let's write the parameters at first, int id and then string name. Okay? And then first thing will be this dot ID is equal to I will name it student ID. Just too, just so that the names are different. And this will be student name. This dot name is equal to 210 name. Now, seeing now we have, it's mandatory to send that to value. The first will be, I guess first is id and second is name. Now I don't have to mention here. And if I run again, you will see same thing. Because if you want to check, I will send a 100. And then let's check the ID. So ID, so this student class now can assign a value. This concept will be used a lot of time while building a yellow application using flutter. Next example, you can just simply see if var student to it so easy now to create objects was written to then 99. And then Mark sucker berg. And then I will just said student to dot name. You will just see, see, this is a constructed two times. It's called because we are creating two objects. That is the main reason. So I hope you have understood the concept of classes, objects, and constructed. You just have to understand this much more V. We'll see where it is being used when we are in the flutter session. So that's all for today. Thank you. 14. Generic Type & Inheritance: Now we will discuss about the next topic, which is what our generic types collections in that are heterogeneous by default. That means collections like list map can contain multiple values of different types. Just for example. Again, I would like to remove all this so that we can understand this concept. Generic type. To usually what happens is if we have a list of, you can say user, then this list can have first string, that is mark. Then second data can be in teacher. And third data can be Boolean. You can say true. Okay? So what happened is we are using, are entering multiple datatypes in debt list, which is okay if that is required by that particular function, you can say a particular task. The concept of genetics can be used to achieve a strictly strictness in the data types. That is, if we mentioned that this user will unlist, user list will only contain strings, then it, then it's makes sure that there will be no error. Vital, we are building that application because we don't want the user, the person who is using our application to just insert whatever they die he wanted to our variables because it will show an error if anyone tries to assign different value in that setting. And a generic type is declared simply using less than, greater than. That is here. List, then string. It means this list will only contain string. Now I have to write. And then jeff, see, now the error is gone because we are doing what is being mentioned in our program. Similarly, if we want, we can just use less of ink. Marks is equal to 33, 44, 55. If I tried to antennae string, it will show an error because the element type string can we assign to that list type integer? So it's very convenient at a lot of times. And also we have discussed list, but what if there is a map? Because map use to be like string name, then a value. Suppose who else is left? I was just like Tom. And then we will let 22 weekend recognizable if it's a normal that we haven't mentioned any type. But if you want to restrict it, then we can just write string will be the key most of the time obviously. And then a value, value will only be string. In that case, this 20 tree will show an adder. We have to give a string. That is suppose age, adult legis. I'm just giving an example. In the same way we have used Enlist and map. Genetics can be used for anything such as glass function object. You might ask me how function that is. If there is a function, I'm just not getting an example right now. But suppose, if there is a function string. List, function name will be whatever. Give, add the data. Then it's, it's the return-type pays a list. But what if we just mentioned list of integer here? So this return should only contain integers like this. So in while venue will see the real flat replication flutter code, you will see this generic type a lot of time. Now, our next concept is about accessibility, which simply means usually if you are coming from another programming language, you must know the concept of public and private. Properties are variables or whatever function. By default, all variables and functions are public and accessible to the object weekly, suppose there is a class. Student. Study class should be like this. So this int id 2 is accessible by its object, like student one dot ID. But if we want to make it a private debt means on the unlit Within this class, this data will be accessed not outside. So in that case, if you, if you can see this here, it's the issue of, you can say normally, this is the issue of dot pad, but let's try and print because in VS Code here if you are able to see that ID. But when we will use a real programming language, you can see when we're working in VS Code, this won't happen because whenever we make any property inside our class, private property, it won't be access by its objects. So my TED is just simply use underscore before the variable name. This is how we make it private. And you might think, no, it's not working here, but this is not true. This is in some issue of trackpad, which will be solved when we are using any text editor. But right now, the only focus should be on understanding the concept. So yeah, we have done this portion that is controlling accessibility, which simply means how to make a variable R function private within the class. Then next concept we will be understanding is what is inheritance? This is another concept into object oriented programming. So suppose we have two class. You can just seen that slide. There are two classes, dog and cat. Within the two glasses data some properties are some methods which are common. We can say first is color and the second is eat. So if there is only one or two pluses, then it's AKI. But what happens if we have multiple classes? And those classes also has those function that is also cat and dog. Okay? But what if there is some leg bird? Then those will also have a coloring in Eat function. So in that case, we can just make a, we can just make an, another class which will be the parent class. You can just send. That class, can be extended or can be copied by its lower classes. So you can just see week, we will make a separate class and put those common characteristics. Let's do it and try. Yes, right? In heavy, dense concept. First of all, I will write the parent class like animal. And then it will have string, color and void. Void. It means this is a function. Now let's see, I have a class of col, of name tag and it will have a property of String breed. And second, it will have wide by property. Let's make it null. Now what happens if I create an object of dog? Dog is equal to dog like this. And then if I tried to access dog dot, it will only show breed and park. But what if we also want that color? In this case, the concept of inheritance comes. Now we just simply have to class extends animal. Okay? This extends keyword is used when we are inheriting. So now if I write doc dot c v, you can see color as well and eat as well. And if you want, we can just directly call the IT function like print eating. And now R1, C, You can see eating. So here dog is called the child class, and this animal is called a parent class. And this class is inheriting from this animal class, inheriting mints, these properties and methods. It can be used within this class as well. So it's good. And this extending will be used in Flutter. I haven't used that much because in Florida everything, they are already being extended. Internally. We just have to write the keyword and that's it. We, it's very rare that we will create our own classes and inherit them. It just depend upon your usage. That said. So I hope you have understood the concept of inheritance and then how to make a variable private like Lex simply this underscore. And that generic type. Generic type is used mostly with list, map and editing. So debts on for the object oriented portion of dark language. 15. Exception Handling using Try Catch: In this session we will be talking about exception handling. So if you are willing any application, definitely there will be times where you will encounter some errors. Are those errors in the programming language, it's called exception. So you can just see the definition here. When a program ends abruptly or have an error, this situation is known as an exception. So definitely everyone knows that there will be an error, so it's better to handle it accordingly so that our application doesn't crashes. Now, what is this try catch block? So by the name only, you can understand it. First, Let's try this block of code. And if there is any added, then catch the error and do something with it. So this is the meaning of this statement. Okay, now, let's try in our dark pad because obviously, it's good if we do that. Now. And it's having a new variable of year 2021. And then int 0 is equal to 0. So I hope you know that numbers cannot be divide by 0. So if we just say int result is equal to IR divided by 0, then at present, it will show infinity, but I will. Okay? Now see our type of double can be assigned to a variable of type int. Because when we are dividing like this, that result will come in a decimal point. To avoid that, we will use this symbol. It does what? It simply gets the first value and you remove the decimal portion. Now, if I run it in the console, you will get this error here and support uncaught error, unsupported operation. So you can see it's already mentioned here that it's an uncut edit. So now to solve this, we will use that a try catch block. And it is written like this. First try and catch is a function. And this E, We will catch them. Or you can say that will be stored in this variable e, so that we can use and predict. Now, let's try this and bring you here. Okay? And we will just right. Now, first I will write handled exception, then E, that is whatever the exception it is there. So a light was red color. Now see, it's a normal printer, printing, not an exception. It's like handled exception and then unsupported operation. So this is the way, how would I take code? For example, just as you, in that try-catch, there is some database call. And obviously there will be times that suppose the server has some matter, the Internet is not working. In that case, we will catch the adder and show some kind of dialogue box are alert to the user regarding that same rather than our application crashes, crashes, and this will be a very bad experience to the user. So you can see from the slide, this is how we handle an exception. Another example of exception can be having a list. So let's assume we have a list of marks and it will contain 30 angle any semi-solid, okay? It will contain three valley. So the index will start from 0 and ended 12. So what will happen? If we tried to print marks tree, which is not there in the list. So definitely it should show an error, but the error is handled. And C, range error, index out of range. Index should be less than three. And if I write two, then simply it will print sum D7 and this catch block, obviously since there is no error, This phone be executed. So I hope you have understood the concept of exception handling using try-catch when you will be working on a third application. This try and catch block will be used intensively because we will make sure no error or no not, no situation should occur where the user should get annoyed and uninstall our application. For, okay, more of this we will learn in the flooded section. That's it. 16. Static variables and methods: So in this session we will understand what does static variables and static methods. So if you heard about this static and things, so it's again the concept of object oriented programming. And let's have a class of students. So now I'm talking about static properties. So just remember the instance variables as well. So water instance variable, If we mentioned like int Marx is equal to 0. This is an instance variable. Okay? And simply, if I want to declare a static variable, I will just write that keyword. And then what should I write? User has marks. I will just write score. Yes, Just for example. This is that tick variable. This static variable, just sweetening keyword static, it becomes a static variable. So you might be thinking, what's the difference? We will just come to that in a while. Now let's have a function that is method as well. Wide. In Greece, Marx, I should just semicolon marks plus plus and saying, I will just say void, increase score, and right, score plus, plus. That is our instance variable. I will just remove all this. Now. In order to access an instance variable, we have to create an object. So we have already done that before. War. String name is equal to, this is an object. And after that, if I write print and I want to print marks, then I will just simply student One dot marks. And this call, I will just do it from ten and I will just say plus 10, that it will just be incremented less than 10, so that we don't get confused. Now. Okay, if I run now, it will print 0. What, what, what if I want to print the score? Then let's try with object. We created student one dot c. If I write dot, then score won't be accessible. Is not accessible because it's aesthetic value. Static property. To access that, we have to directly do it from the class name that is student, is that class name then dot Dense core C. So that's different approach or a different concept. You have to remember that if we want to access instance variable, then we have to make an object first. But if we have a static variable, then we don't have to create any object to that class directly. We can access the value. Okay? If you have understood till now. Now, I would like to do what I would like to access to an end one dot in Greece, Marx. And I will read student one dot increase. So it is Turin spelling wrong. Student one dot increase core. Okay? And then again, I will just put in our values here. But I hope you know what will be the answer. It will be then 12 indeed, down here, 120. Okay? Now, let's do one thing. We will create another object. Var student two is equal to. Student, Okay, we have a new object. Then if I write print student to dot marks. And then to then do, I will do increase score. Okay, that is the static variable, but I am doing it with the second object. So in your mind, you might think, now if I again print, if I again print, does that depicting a Phi, now we're into static thing. Then it shoots just have this score is 10. And then again to indeed, because it's a new object, Let's run. But you will just see the difference here. See this marks student to that Marx is 0. But this student dots score is continuation. That is, from first object we did some changes from second object world, so did some tenuto static variable. But all that debugged year will be different objects, but the value will be seen. But in case of an instance variable, it will again start from 0. So that is the main difference between static instance variable. Debt is instance variable will be called or will be initiated multiple times, but it's static value will be initialized to one. Then after the same data will be fetched from the memory, at least it will live memory efficient because most of the time we know gather some data which won't be changed in that class. Suppose there is a student, then the college name suppose won't change, are, suppose there is a bank class bank. That name of the bank are something which is unique and won't change. So what we do, we may not want to use the memory of creating it again and again. In that case we use the static keyword. I hope you have understood that it's just the difference that an instance variable consumes more memory because EBIT every object, it is initialized from 0, that is from the beginning. But the static we'll just get big continued. The same value will be continued. Now, you have understood static properties that these t's. Now it's time you understand static. Well, what it's called the method, simply just write the static keyword before a method. That's it. But if you make it static, definitely it won't be accessible through the object. So I won't suggest to change this, but I will just have static, void, string, college return. Okay. Now to access that, we simply have to just read print student college like this. So just remember, this is not an object. We are directly accessing it through its class name. Object is this. And this. These two are objects which can only access directly the instance variable or the instance. My kids. I will just write it here. It is instance method. This is instance my time, but this is static method. So this is, this was the logic behind decimal static and instance keywords. I hope you have understood and enjoyed till now. Now, we are just about to end our course. And after that, we will directly deep dive into Flutter. 17. Ternary operator and Null safety: Now lastly, only a very few concepts are left, are tough them. The first concept is called a ternary operators. So I will just write ternary operator. So you might ask, what is a ternary operator? It is nothing but in evade to write if else statement. So you just know how to write differs this if. And then here as simply like this. Suppose I have a value int age is equal to 25. To here. I will just write if age is 18, print allowed, suppose. And then if not, print not allowed. Okay? So this is our normal if else statement to you might be asking what is a tornado return? So ternary operators are used to just scattered down that code we write or to just make sure it's very clean. When we write it. It doesn't, it's not like it's not taking too much space. It's just the right age. Greater than 18. If it's true, then print. Yes. Else print. No. See, this is the ternary operator. L is French in here again, this, and then this run Gender Program. And see we have the output, yes. So ternary operator is a way to write the if-else statement. And yes, you will be using it a lot of time because you can just see the difference. Figure own eyes. That is just a one line of code. Earlier we have two roots, so many code to do the same thing. So just written like the condition then the quotient map. That is, if the condition is true, then what we have to do, and with this column, it means if this condition is not true, then what we have to do, simple as that. Now, this ternary operator is over, the concept is over. After that. Our final and important concept is null safety. Earlier also you have used this null safety, if you remember, it was the quotient mark in that either type, which means you can contain null as well. This null safety was introduced very recently. So if you go back, six months back, or in the beginning of the end of 2020, you can say you won't be hearing or you you won't be using this notes safety because it was not in the production mode. It happened on March 2021. The concept of null safety was introduced officially. When we declare any variable, it can contain value or can be left null by default. This may create errors when we're in that. That is why the concept of null safety was introduced. Now when we declare any variable, it is assumed that it will not be null unless we declare using certain keyword, which we will discuss later on. Now safety was already activated. See here, downs. It was already activated here. And in flutter, it's on by default, so you, you have no other choice of removing. So what was introduced in the null safety concept here with some new keywords or operators. First is this question mark, which we have used before. We use it to denote the variable can continue. Real value can be null as well. In this, in this case, we already know that value can be null and we will handle that accordingly. There will be no scope for any unknown exception, edit integrand tank. Because I lead to as Lake, there was a variable, suppose string which will contain a user ID. And if that is null, then it will be a lot of trouble because we won't be able to fetch any information from our database without the user ID. Let's write it down. Let's write if this string friend is equal to Elon Musk, okay? Then, then it's not showing any error. But what will happen if we write if string is null? Now this will show an error because we cannot assign a value to a string. But if we, if we know that this value may be null, then we have to use this operator. Now, there isn't an issue. I then this friend variable will be null. This friend variable will contain a string like this. So this is the use of the quotient mark keyword. Let's do it. Let's do some more thing. Suppose we have a function set friend. It will contain a name and it will not, it will accept a name. And we will just say name dot toUpperCase. And we will call this function here. Let's run. I just made it. Now let's run. Obviously. That function was not, was written below, so it was showing an adder. Now, what will happen if we tried to send a null value? In this case? Now it will show an error because null cannot be sent to a string. But if we make it null safety, this area will be gone, but the error will be here because if it's null, then how this function will be executed. Because we're seeing that the num name variable will be null. But again, there will be added as we have some kind of function. To tackle that. We have to check here. If name is equal to null, then here only I will return the function and not execute below. So now this is a proper way of checking if the value is null or not. So this concept is very important. And there is another keyword to check. If a value is null, R naught, which is this keyword, quotient mark and dot, which will we use. Now, let's see. See null. So it's checking whether this name is null or not. If it's null, then just sprint out null are, if it's a name that is Bill Gates, then what will happen? It will execute the function. This is a better way to just check the null. Null. What you say, if any variable is null or not. After that, the next key word is required. This is a, this is a change which is being done in that code. If you remember how, what, where, name, arguments. It will just like this and just say string name and print your name. It will show an error because the name can be value, can be null. So either we have to use this question mark. To solve this. Are we have we simply write required keyword here. Yes, this keyword, which simply means we have to send a value. We cannot just send it to this function. So debt is the user required keyword mostly in that time swear the values can be optional. That is in name parameter r. If you don't want to write, they don't want to write require, then the other thing is just to give a default value that is supposed guest, like this and it will be equal. So this is a default value. If the string name is containing null, I will just go and test my name and send here. Sorry, it should be at least string. If I am not sending anything, then it will be name. Because I'm not saying it will be null by we can make it optional. And if I write P learn mask, then what will happen? It, since it's a name argument, it should be like this. C value we're programming. We have to just make sure we don't do all these kind of mistakes. You have to remember the difference between a name variable, name parameter and a positional parameter. So I hope you have understood a little bit about safety thing because this concept is very much important. After that, then next keyword, which is this exclamation to tell the compiler that we are very sure that you will not be null. We are confident that variable will always hold a value. Then only we will use this keyword. Let's try it off our own. Now, let's suppose we have this thing. New name, variable which can be null. We have right here. And what will happen if I send this string to them, my name function, which also accept a name parameter, which is a string. If I just write new name, here, you will see it will show an error because we are sending a string that is a nullable string to a string. But what will happen if we just keep an exclamation here? Which means we are very sure that this is having a value. So to make sure we have some thing, they're very much sure that you will not be null in the future. Also, we use this exclamation. But remember this exclamation is a very tricky thing. Because if we are wrong with our thing, retire debt means if you are saying that value will not be null, and if the value is null, then we will have this kind of errors in our application, which is not good. So you might be thinking that it's too much to digest, but just have some patients because definetly. When we are in the flutter course, we will understand all these concepts very clearly. So we have understood keywords like question mark, exclamation, then the required keyword. Now then last change is the late keyword. It's very simple. This keyword is used when we are assured that we will initialize the value of that variable later on. Which means, no matter what, when the object of that class is spin created, we will initialize our v, will make sure that variable is not null. So just remember if you let her forget to a sender valid to a string or a variable, it will show error. So if you have a class of students, we can just write late int id, like this, late, sorry string name. And this means this ID will be printed. Saudi will not be left null, no matter what. So if we have print id function, right, But int id. So then it's fine. It will not show any era, but if we remove the late button, see, then it will then DID is an error because it's showing that first, please have a value here like do tree, like this. But using the let keyword, we can remove this editor and just say to the compiler that don't take this much stress. We know that this variable is important and we will make sure it has a value at the end of the object creation. So that's it. These were the concept of null safety. And this way, this was the final topic of the dark course as sweat. If I feel like if I have to add anything in future, I will definitely add it. But right now we are good to go directly into the flutter course. Thank you.