I will not focus very deeply on very basic things like variable declaration and keywords etc. You can find all of this basic syntax on the website of dart so, I will tell you only some important point about the basic syntax, and then we will move to more important Object-Oriented Concepts of Dart which will be useful in creating Apps using Flutter.
So let's start with the step-by-step coverage of the syntax which is of C style.
Any Dart program has the entry point at its main( ) function. So for any program to run, there must be the main function.
So now let's enter the program and discuss further.
Next thing that we need is variables. When we declare variable then we are doing nothing but allocating some space in memory or think of it as a box which can hold some item in it.
So next question that comes to mind is how we declare variables. So there are different methods to declare variables.
So let's start with the step-by-step coverage of the syntax which is of C style.
Any Dart program has the entry point at its main( ) function. So for any program to run, there must be the main function.
main() {
//Here goes your code
}
So now let's enter the program and discuss further.
Next thing that we need is variables. When we declare variable then we are doing nothing but allocating some space in memory or think of it as a box which can hold some item in it.
So next question that comes to mind is how we declare variables. So there are different methods to declare variables.
- If we don't know which type of data we will store in that variable then we can use the var keyword, which can take any data type.
- If we know which kind of data we want to store then we have many different data types such as String, num(accept both integers and double), bool (true or false)etc.
Now as we have declared variables we can assign the value using = operator where the value on RHS is stored to LHS.
Now if we have declared any variable then we will have to use it somewhere so to access the value we use the $ sign before the variable name to access the value stored in that variable name.
String name = "Light";
String lastName = "Yagami";
int age = 25;
print("$name $lastName is $age");
print("Hello there $name ${lastName.toUpperCase()}");
//The output of the first print statement will be :
//Light Yagami is 25
// and second will be:
// Hello there Light YAGAMI
As you have noticed that we have used {} in the second print statement if we don't
use it then it will not be considered as a complete expression and it will simply
act as string concatenation.
There are two more important keywords that are important:
- const: When we declare any variable with const before it then we want the value of that variable to be constant at compile time.
- final: When we declare any variable with final before it then we want the value of that variable to never change.
I know that it is looking very similar at this time but don't worry, when we will start using them in flutter then it will make more sense.
I know that I am skipping many topics but those topics you can read from the dart website and you are free to ask any doubt in comments related to these topics.
In the next part, we will talk about the control flow and functions in the dart. Till then enjoy learning dart and practice as much as you can.
Comments
Post a Comment