This video for dart beginners!
1 → Main method
The main() function is a top-level function in Dart that initiates the execution of the program. It is the Dart programming language’s most important and crucial feature. In a program, the main() function can only be used once.
void main(){
// your code here
}
1.1 picture is shows syntax for the main function. you can start write your code in the your code aria.
Hello world with dart?
void main(){
print("Hello world")
}
1.2 picture is shows how to write Hello world! with dart you can use print function for it. it like to python but you need write semicolon after coding sentence.
2 → Variables
2.1 picture is shows part for the variables. you can make variable using that type.
example is → String myName = “manape”;
3 → Basic Data type
String → string is traditionally a sequence of characters, either as a literal constant or as some kind of variable
int → whole rounded number include for the int datatype
double → double declare floating point numbers(12.34, 23.34,56.76)
examples:
void main(){
String name = "man ape"; // this is string data type
int number = 10; // this is int data type
double dounum = 12.34; // this is double data type
}
4 → String connection and interpolation
3.1 String connection
can make string connection using ‘ + ’ mark. it also link python string connections. we can use it with variable or with print function.
example:
Input:-
void main(){
String name = "man " + "ape";
print("Hello " + "World")
print(name);
}
Output:-
3.2 → String interpolation
String interpolation is the process of inserting variable values into placeholders in a string literal.
So easy to make String interpolation with dart language. we use ‘ $ ’ sign for it. it is so make easy way to our coding works.
How use it?
void main(){
String name = "man ape"; // this is string data type
int number = 20; // this is int data type
double dounum = 12.34; // this is double data type
print("My blog name is $name");
print("My age is $number and my double number value is $dounum");
}
3.1 picture is shows how use string interpolation you can test your code your self it so easy i think you can understood it well. this method with can
If you went use string method with that you have to another interpolation for it
we can use ‘ ${} ’ interpolation for it.
example is:
input:
void main(){
String name = "man ape"; // this is string data type
print("my blog name is ${name.toUppercase()}");
}
output:
it so easy you can use different type string operators with it. you can see different strings methods with this link: api.dart.dev/stable/dart-core/String-class...
5 → String escaping
you can print special characters using back slash 3.1 picture have example for it.
input:
void main() {
print('i\'m manape');
print("i'm manape");
print("10\$");
print("\\");
print(r"c:\windows\file");
}
output:
6 → String operators
string operators so useful thing with string operator we can do different things. you will can understand it with down picture
void main() {
double temp = 20;
int value = 2;
String pizza = 'pizza';
String pastaa = 'pasta'.toUpperCase();
print("The tempurage is ${temp}C");
print("$value plus $value make ${value + value}");
print('i like ${pizza.toUpperCase()} and $pastaa');
// finding
String sen = "i like drink a tea";
print(sen.contains("tea"));
// replace
String pasta;
String food = "chiken";
pasta = sen.replaceAll("tea", "fresh milk");
print("you also like ${food} and " + pasta);
}
7 → Arithmetic operators
8 → Ternary access operator
This is syntax of ternary access operator
This this example for it:
input:
void main() {
int x = 19;
String type = x > 10 ? 'adult' : 'child';
print(type);
}
output: