Unit: 1.1 Introduction To Flutter: Prof. Mehul Bhundiya
Unit: 1.1 Introduction To Flutter: Prof. Mehul Bhundiya
(MADF) (2101CS402)
Unit : 1.1
Introduction to
Flutter
Program Output
1 void main(){ 1 Darshan University
2 String str = 'Darshan University'; 2 Darshan University is at hadala
3 String str1 = 'is at hadala';
4 print(str);
5 print(str + str1);
6 }
Program Output
1 void main(){ 1 false
2 String str = 'Darshan University';
3 String str1 = 'is at hadala';
4 bool val = (str==str1);
5 print(‘$val’);
6 }
Example Example
1 class Student { 1 std.stdAge =24;
2 var stdName; 2 std.stdRoll_nu = 90001;
3 var stdAge; 3 //Accessing class Function
4 var stdRoll_nu; 4 std.showStdInfo();
5 5 }
6 // Class Function
7 showStdInfo() {
8 print("Student Name is : ${stdName}");
9 print("Student Age is : ${stdAge}"); Output
10 print("Student Roll Number is : $ 1 Student Name is : Darshan
11 {stdRoll_nu}"); 2 Student Age is : 24
12 } 3 Student Roll Number is : 498
13
14 void main() {
15 // Creating object called std
16 var std = new Student();
std.stdName = “Darshan"; #2101CS402 (MDAF) Unit 1 – Introduction to dart programming
Prof. Mehul Bhundiya 13
Sound null safety
Null Safety in simple words means a variable cannot contain a ‘null’ value.
It prevents errors that result from unintentional access of variables set to null.
There are two types on variables:
Non-nullable types
Nullable Types
Program Output
1 var lst = new List(); 1 [12, 13, 11]
2 lst[0] = 12;
3 lst[1] = 13;
4 lst[2] = 11;
5 print(lst);
Program Output
1 void main(){ 1 {First: Darshan, Second: University}
2 Map<String,dynamic> gfg = Map();
3 gfg['First'] = ‘Darshan';
4 gfg['Second'] = ‘University';
5 print(gfg);
6 }
Syntax
1 if ( condition )
2 {
3 // statement(s) to be executed
4 }
Program Output
1 void main(){ 1 8 is greater than 5
2 int a = 8;
3 // Condition is true
4 if (a > 5) {
5 print(" $a is greater than 5");
6 }
7 }
Program Output
1 void main() { 1 The condition is true
2 int a= 15;
3 if (a > 10) {
4 // This will be printed
5 print("The condition is true");
6 } else {
7 // This will not be printed
8 print("The condition is false");
9 }
10 }
#2101CS402 (MDAF) Unit 1 – Introduction to dart programming
Prof. Mehul Bhundiya 25
if else if statement
The if else if statement checks the condition and, if it is true, executes the statements within
it.
If it is not, other if conditions are check, and if they are true, they are executed.
It’sSyntax
useful when we have to choose between more than two options.
1 if ( condition1 ){
2 // body of if
3 }
4 else if ( condition2 ){
5 // body of if
6 }
7 else if ( conditionN ){
8 // body of if
9 }
10 .
11 .
12 else {
13 // statement
14 }
Division (Integer Division) Use two divide two operands but give
~/
output in integer
% Modulus Use to give remainder of two operands
Program Output
1 void main() 1 true
2 { 2 true
3 String a = 'GFG';
4 double b = 3.3;
5
6 // Using is to compare
7 print(a is String);
8
9 // Using is! to compare
10 print(b is !int);
11 }
#2101CS402 (MDAF) Unit 1 – Introduction to dart programming
Prof. Mehul Bhundiya 35
Bitwise Operators
Operators which are used to perform bitwise operation on the operands.
Program Output
1 void main() 1 35
2 { 2 12
3 int a = 5; 3 12
4 int b = 7;
5 // Assigning value to variable c
6 var c = a * b;
7 print(c);
8 // Assigning value to variable d
9 var d;
10 d ? ? = a + b; // Value is assign as it is null
11 print(d);
12 }
#2101CS402 (MDAF) Unit 1 – Introduction to dart programming
Prof. Mehul Bhundiya 38
Logical Operators
Operators which are used to logically combine two or more conditions of the operands.
The above syntax implies that if a certain condition evaluates to true then we evaluate the
expressionOne first and then the expressionTwo.
Program Output
1 void main(){ 1 Answer is 10
2 var ans = 10;
3 ans == 10 ? print("Answer is 10") : print("Oh no!");
4 }
The only difference is that in the above syntax if expression1 is not null, then it gets
evaluated else expression2 is evaluated.
Program Output
1 void main(){ 1 Hello
2 var b;
3 String a = b ?? 'Hello';
4 print(a);
5 }
Control flow:
1) initialization
2) Condition
3) Body of loop
4) Test expression
The first is executed only once i.e in the beginning while the other three are executed until
the condition turns out to be false.
In each iteration, one property from the object is assigned to the variable.
This loop continues till all the properties of the object are exhausted.
Program Output
1 void main() { 1 12
2 var obj = [12,13,14]; 2 13
3 for (var prop in obj) { 3 14
4 print(prop);
5 }
6 }
f( value): It is used to make a call to the f function for each element in the collection.
Program Output
1 void main() { 1 12
2 var obj = [12,13,14]; 2 13
3 obj.forEach((var num)=> print(num)); 3 14
4 }
A function declaration tells the compiler about a function's name, return type, and parameters.
function_name defines the name of the function.
return_type defines the datatype in which output is going to come.
return value defines the value to be returned from the function.
The info function takes an optional named argument as its second argument.
Program Output
1 void main() { 1 Example of anonymous function
2 var list = ["James","Patrick","Mathew","Tom"]; 2 0: James
3 print("Example of anonymous function"); 3 1: Patrick
4 list.forEach((item) { 4 2: Mathew
5 print('${list.indexOf(item)}: $item'); 5 3: Tom
6 });
7 }
8
We have a helper buildMessage function which is defined inside the main function.