Dart Programming

 1.      Printing to the console in Dart programming

Void main()

{                                                                                                     

print(“Heloo world”);

print(“Batman”);

print(“Batman”);

print(“Batman”);

print(“Batman”);

print(“Batman”);

}

Output:

Heloo world

Batman

Batman

Batman

Batman

Batman

Description: when used in console based application it outputs in the terminal console.

2.       Comments -dart programming

//     Singleline comment

/* */   Multiline comment

Description: Just put two slash symbols at the beginning of the line you want to comment out. //This is a comment.(single line Comment), his method is usually used to comment out a block of code.(multiline comment).

3.       Print Variables Inside  to a String

·         Void main()

{

var  x=10;

var y=”Hello world”;

print(x);

print(y);

}

Output:

10

Hello world

·         Void Main()

{

Var  age=18;

Var  food=”pizza”;

Print(“Iam $age and I love eating $food”);

}

Output:

Iam 18 and I love eating pizza

·         Void main()

{

Var  age =90;

Var  food=”Pizza$age”;

Print(“Iam $age and I love eating $food”);

Print(food);

}

Output:

Iam 90 and I love eating pizza 90

Pizza 90

            Description: Variables used to print the value of the int along with the string.

4.      Console  Input – Dart programming

·         import  ‘dart:io’;

void main()

{

String str=stdin.readLineSync(); //Input should be given in console

Print(str);

Print(“End of  application”);

}

Output:

 Hello

Hello

End of application

                Description: The readLineSync() method of stdin allows to capture a String from the console

5.       Variables – Dart Programming

·         Void man()

{

Var epicName;

epicName=”Hello world”; or  var epicName=”Hello world”;

print(epicName);

}

Output:

HelloWorld

 

·         Void main()

{

String  epicName=”Hello world”;

epicName=89;

print(epicName);

}

Output:

Error compiling to javascript: Error: A value of type ‘dart.core::int’ can’t be assigned to a variable of type, ‘dart.core::string’.epicName=89;

·         Void main()

{

int epicName=90;

epicName=89;

print(epicName);

}

Output;

89

·         Void main()

{

Var epicName=”Hello world”;

epicName=”Batman”;

print(epicName);

}

Output:

Batmen

·         Void main()

{

Var epicName=90;

epicName=80;

print(epicName);

}

Output:

80

Description:  use the var keyword to define variables. once assigned a type is assigned you    can’t reassign a value with new type to the variable. Dart automatically infers the type of data from the right hand side.You can also define variables by explicitly providing type of data.

6.      Final and constant Variables – Dart programming

·         Void main()

{

Final var  v1=9;

Const var  v2=10;

V1=8;

V2=2;

Print(v1);

Print(v2);

}

Output:

Error:Setter not found:’v2’.

·         Voidmain(){

Const pi=3.1456;

final v1=9;const v2=10;

print(v1);print(v2);}

 output:Error

·         Int Epic()

{

Return 1;

}

Void main()

{

final v1=Epic();

const v2=89;

print (v1);

print(v2);

}}

Output:

1

                89

Description: const variables must have a value during compile time, for example  const PI = 3.14; , whereas variables that are final can only be assigned once, they need not be assigned during compile time and can be assigned during runtime.

7.       Static vs Dynamic Variables – Dart Programming

·         Class Epic

{

Var satus=0;

Static var statics=0;

epicFun()

{

Status++;

Statics++;

Print(‘status:$status & statics:$statics’);

}}

 

·         Void main()

{

Print(“E1”);

Epic e=new Epic();

e.epicFun();

e.epicFun();

e.EpicFun();

Print(“E2”);

Epic e2=new Epic();

e2.epicFun();

e2.epicFun();

e2.EpicFun();

}

Output:

E1

status:1 & statics:1

status:2 & statics:2

status:3 & statics:3

E2

status:1 & statics:4

status:2 & statics:5

status:3 & statics:6

Description: Dynamic you can access the methods and properties of it's type. But static doesn't allow to access it.

8.      DataTypes- Dart programming

·         Void main()

{

Int i=4;

Print(i);

Double d=9.5;

Print(d);

String s=”Hello world”;

Print(s);

bool  b =true;

print(b);

}

Output:

4

9.5

Hello world

True

Description:  basic data types that you can expect from a modern language.

  • Numbers
  • Strings
  • Booleans

9.      Boolean –Dart programming

·         Void main()

{

bool  var1;

Var2=67>89;

Print(var1);

}

Output:

False

·         Void main()

{

bool  var1;

Var2=67>89;

Print(var1);

}

                Output:

                True

Description: Boolean has trueb or false parameters,

10.  Numbers –Dart Programming

·         Void main()

{

String str =”5”;

int  i=num.parse(str);

print(i);

double d=9.5;

print(d);

}

Output:

5

9.5

·         Void main()

{

String str=”-5”;

int  i=num.parse(str);

print(i);

double d=num.parse(“6.78”);

print(d);

 print(d.round());

print(d.truncate());

print(i.isNegative);

Output:

-5

6.78

7

6

True

Description: Number is one of datatype contains int ,double,negative,round and truncate.

11.  Arithmetic  Operators

·         Void main()

{

int num1=10;

int num2=5;

print(num1+num2);//addition

print(num1-num2);//substraction

print(num1*num2);//multiplication

print(num1/num2);// division

print(num~/num2);//integer division

print(num1%num2);//modulous 0

print(-num1); -10             //if num1 is -10 output is 10

//increment ++

Print(num1);//10

Num1++;

Print(num1);//11

                //decrement –

Print(num2);//5

Num2--;

Print(num2);//4

int numExtra=8;

print(numExtra++);//8

print(numExtra);//9

 

int numExtra=8 ;

print(++numExtra);//9

print(numExtra);//9

}

Output:

15

5

50

2

2

0

-10

 10

11

5

4

Description:Arithmetic operators included +,-,*,/,^,&. An expression is a special kind of statement that evaluates to a value. Every expression is composed of −

·        Operands − Represents the data

·        Operator − Defines how the operands will be processed to produce a value.

Consider the following expression – "2 + 3". In this expression, 2 and 3 are operands and the symbol "+" (plus) is the operator.

 

12.  Strings – Dart Programming

·         Void main()

{

String str=”Hello world”;

print(str);

String str2=’You\’re’;

print(str2);

String str2=”You’re”;

print(str2);

 

String str3=”””Hello world”””;

print(str3);

String str4=’’’Hello Hi world’’’;

print(str4 );

}

Output:

Hello world

You’re

Hello

      World

Hello

     Hi

     World

·         Void main()

{

String name=”Batman”;

String str1=”Hello ”;

String str2=”wo${name}rld”;

String result=str1+str2;

Print(result);

}

Output:

Hello WoBatmanrld

·         Void main()

{

String name=”Batman”;

String str1=”    Hello    ”;

String str2=”wo${6*6}rl$(name)d”;

String result=str1+str2;

Print(result);

Print(str1.length);

Print(str1.toLowerCase());

Print(str1.toUpperCase());

Print(str1.trim());

}

Output:

      Hello    Wo36Batmanrld

12

       hello

       HELLO

Hello

Description: A string can be either single or multiline. Single line strings are written using matching single or double quotes, and multiline strings are written using triple quotes.

13.  Relational Operators –Dart Programming

·         Void main()

{

Int num1=5;

Int num2=5;

Print(num1>num2);GT

Print(num1<num2);LT

Print(num1>=num2);GE

Print(num1<=num2);LE

Print(num==num2); EqualTo

Print(num!-num2);not equalto

Output:

False

False

True

True

True

False

Description: Dart operators are as follows:

·         ==: For checking whether operands are equal

·         !=: For checking whether operands are different

For relational tests, the operators are as follows:

·         >: For checking whether the left operand is greater than the right one

·         <: For checking whether the left operand is less than the right one

·         >=: For checking whether the left operand is greater than or equal to the right one

·         <=: For checking whether the left operand is less than or equal to the right one.

14.  Type Test Operators

·         Void main()

{

int  i=10;

Print(i  is! String);//Is Type

Print(i  is! String);//is not type

}

Output:

False

True

Description: The Type test operators are used to check type of an object. These operators are handy for checking types at runtime.

15.  Logical Operators

·         Void main()

{

Int num1=10;

Int num2=5;

Print(num1>num2 && num1<20);// And operator

Print(num1>num2 || num1<20);//OR operator

Print(!(num1>num2));//NOT!

}

Output:

False

True      false

Description: Short-circuit Operators (&& and ||) The && and || operators are used to combine expressions. The && operator returns true only when both the conditions return true.

16.  Assignment operator

·         Void main()

{

int  i=20;

int  j=7;

j ??=10;

print(j);         //7

int num1=10;

print(num1);//10

num1 +=5;                //num1=num1+5;

print(num1);   //15

//substract

int num2=10;

print(num2);//10

num2 -=5;                //num2=num2-5;

print(num2);   //5

//multiply

int num3=10;

print(num3);//10

num3 *=5;                //num2=num3*5;

num3 *=5;               //250

print(num3);   //50

//Divide

double num4=10;

print(num4);

num4 /=5;                //num2=num2/5;

print(num4);   //2

}

Output:

7  

10

15

 10

 5

 10

 50

 10

 2

Description: Assignment operators are used in flutter to assign right side operand value to left side operand. The basic assignment operator in flutter is =(Equal). Equal is assign right side value to left side operand without any modification.

17.  Conditional Expressions

·         Void main()

{

Int num1=980;

Var result=num1<100? ”It is less than 100” : “It is more than 100”;

Print(result);

Int num2=null;

Var result2=num2??”It is null”;

int num3=7;

Var result2=num3??”It is null”;

Print(result2);

}

Output:

It is more than 100

It is null

7

Description: The ternary operator is technically that: an operator. But, it's also kind of an if/else substitute. It's also kind of a ?? alternative, depending on the situation. The ternary expression is used to conditionally assign a value. It's called ternary because it has three portions: the condition, the value if the condition is true, and the value if the condition is false.

18.  Bitwise Operators

·         Void main()

{

Int num1=55;

Int num2=78;

Print(num1&num2)//bitwise and&    6

Print(num1|num2)//bitwise Or|      127

Print(num1^num2)//bitwise Xor^     121

Print(~num2);      4294967217   

Print(num1<3);    false ;

}

Description: You can manipulate the individual bits of numbers in Dart. Usually, you'd use these bitwise and shift operators with integers.    

19.  Conditional IF statement

·         Void main()

{

int num1=100;

if(num1==0)

{

Print(“it is 0”);

}

else if(num1==10)

{

Print(“it is 10”);

}

 

else if(num1>=50)

{

Print(“Greater than 50”);//100 greater than 50

}

else

{

Print(“Default”); 45 lesser than 50 its default

}

}

Description: In normal If condition there are two parts If part and Else part. If the given condition is True then it will execute the If body part statements. If the given condition is False then it will automatically execute the Else part. 

20.  Switch statement – Dart programming

·         Void main()

{

  Int x=8;

Switch(x)

{

Case 0:print(“0”);

Break;

 

Case 1:print(“1”);

Break;

Case 2:print(“2”);

Break;

Case 3:print(“3”);

Break;

Default:print(“default”);

Break;

}}

Output:

8

Description: The switch statement evaluates an expression, matches the expression’s value to a  case clause and executes the statements associated with that case.

21.  For in loop

·         Void main()

{

Var i=[1,2,3,4,67,89,0];

for(  var val in i)

{

Print(val);

}}

Outpuyt:

1

2

3

4

67

89

0

Description: Dart for in loop is also a loop but a bit different than conventional for loop. It is mainly used to iterate over array’s or collection’s elements. The advantage for in loop has over the conventional for loop is clean code means fewer chances of error and more productivity. 

22.  For loop

·         Void main()

{

For(int i=0;i<=10;i++)

{

Print(i); 1 to 10

Print(i*i);   1 4 9 19 25 36 49………………………………..

}}

Output:

1 4 9 19 25 36 49……………………………….

Description:Use for loop directly inside a Column/ListView's children. . It is mainly used to iterate over array’s or collection’s elements.

23.  While loop

·         Void main()

{

Int i=0;

While(i<=100)

{

Print(i*i);

i++;

}}

Output:

1 4 9 25 36……………………100000

Description: while loop executes its code block as long as the condition is true. The functionality of while loop is very similar to for loop but in while loop first the condition is verified then while loop code block is executed and later on incremental/ decremental variable value is changed to control the flow of while loop.

24.  Do while

·         Void main()

{

Int i=0;

While(i<=100)

{

Print(i*i);

i++;

}

int x=10;

do

{

Print(x*x);

i++;

}

While(i<=5);

}

Output:

0

1

4

9

16

25

0

1

4

9

16

25

·         Void main()

{

int x=10;

do

{

Print(x*x);

i++;

}

While(x<=5);

}

Output:

100

Description: Do…while loop is similar to the while loop except that the do...while loop doesn’t evaluate the condition for the first time the loop executes. However, the condition is evaluated for the subsequent iterations. In other words, the code block will be executed at least once in a do…while loop.

25.  Break statement

·         Void main()

{

for(int i=0;i<=5;i++)

{

If(i==3)

{

Print(“Before break”);

Break;

Print(“after break”);

}

Print(i*i);

}

Print(“outside of loop”);}

Output:

0

1

4

Before break

outside loop

Description: The break statement is used to take the control out of a construct. Using break in a loop causes the program to exit the loop.

27.Continue statement

·         Void main()

{

for(int i=0;i<=5;i++)

{

If(i==3) //skip 3 and continue from 4

{

Print(“Before break”);

continue;

Print(“after break”);

}

Print(i*i);

}

Print(“outside of loop”);}

Output:

0

1

4

Before break

16

25

Outside of loop

Description: The continue statement skips the subsequent statements in the current iteration and takes the control back to the beginning of the loop. Unlike the break statement, the continue statement doesn’t exit the loop. It terminates the current iteration and starts the subsequent iteration.

   28. Basic Function:

·         void main()

{

Epic();

}

Void  Epic()

{Print(“Hello world”);}

Output:

Hello world

Description: Dart language is the base of Flutter. Hence creating functions in Flutter is the same as creating functions in Dart. In this blog post, let’s check how to create and use functions in Flutter. I hope it will be helpful for those who are new to Flutter.

29. Function Parameters

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99,0);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

}

Output:

12

-7

99

Description: Functions can have two types of parameters: required and optional. The required parameters are taking the front row, followed by any optional parameters.

        30.Functional optional named parameter

·         Void main()

{

Add(num2:5,  

num1:8,

num3:7);

}

Void Add(int num1,{int num2,int num3})

{

Print(num1);

print(num2);

print(num3);

}

Output:

8

5

Description:

31. Function Optional Positional parameters

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99,0);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

} 

Output:

12

-7

99

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

} 

Output:

12

-7

Uncaught exception:

Invalid argument:null

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99);

}

Void Add(int num1,[int num2])

{

Print(num1);

Print(num2);

}

Ouput:

5

7

-9

2

99

Null

32.Function Return values

·         Void main()

{

Add(10,9);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

}

Output:

19

·         Void main()

{

int result=Add(10,9);

print(result);

print(result*result);

}

int Add(int num1,int num2)

{

return num1+num2;

}

Output:

19

361

Output: Functions in Dart are as simple as it can get, somewhat similar to javascript. All you need to do is provide a name, a return type and parameters.

33. Function Recursion

·         Void main()

{

Int res=calculateFactorial(6);

Print(res);

}

Int calculateFactorial(int n)

{

Print(“Hello”);

If(n<=0)

{

return 1;

}

else

{

Int result=(n*calculateFactorial(n-1));

return result;

}}

Output:

Hello

Hello

Hello

Hello

Hello

Hello

2

·         Void main()

{

Int res=calculateFactorial(15);

Print(res);

}

Int calculateFactorial(int n)

{

Print(“Hello”);

If(n<=0)

{

return 1;

}

else

{

Int result=(n*calculateFactorial(n-1));

return result;

}}

Output:

1307674368000

Description: Dart Recursion is the method where a function calls itself as its subroutine. It is used to solve the complex problem by dividing it into sub-part. A function which is called itself again and again or recursively, then this process is called recursion.

35. Lamda Function –Dart programming

·         Void main()

{

Epic();

}

Epic()=>print(“we are epic”);

String EpicReturn()=>”Hi”;

Output:

We are epic

Hi

Description: Lambda functions are also called Arrow functions. But here remember that by using Lambda function's syntax you can only return one expression. It must be only one line expression. Just like normal function lambda function cannot have a block of code to execute.

36. Try on block –Dart programming

·         Void main()

{

Int num1=10;

Int num2=6;

try{

print(num~/num2);

}

Catch(error)

{

Print(error);

}

 Print(“End of application”);

}

Output:

1

End of application

·         Void main()

{

Int num1=10;

Int num2=6;

try{

print(num~/num2);

}

On IntegerDivisionByZeroException

{

Print(“create divide by zero”);

}

 Print(“End of application”);

}

Description: The try block embeds code that might possibly result in an exception. The on block is used when the exception type needs to be specified. The catch block is used when the handler needs the exception object. The try block must be followed by either exactly one on / catch block or one finally block

37. Try catch block- Dart programming

·         void main()

{

Int num1=10;

Int num2=0;

Print(num1~/num2);

try

{

Print(num~/num2);

}

Catch(error)

{

Print(error);

}

Print(“End of application”);

}

Description: The try block embeds code that might possibly result in an exception. The on block is used when the exception type needs to be specified. The catch block is used when the handler needs the exception object. The try block must be followed by either exactly one on / catch block or one finally block.

38. Finally Block –Dart programming

·         void main()

{

Int num1=10;

Int num2=5;

Print(num1~/num2);

try

{

Print(num~/num2);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“Finally”);

}

Print(“End of application”);

}

·         void main()

{

Int num1=10;

Int num2=0;

Print(num1~/num2);

try

{

Print(num~/num2);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“Finally”);

}

Print(“End of application”);

}

Output:

Unsupported operation:Result of truncating

Division is infinity:10~/0

Finally

End of application

            Description: The finally block includes code that should be executed irrespective of an exception's occurrence. The optional finally block executes unconditionally after try/on/catch.

39. Try on catch block –Dart programming

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

print(num1~/num2);

double number=double.parse(pi);

print(number*number);

}

On IntegerDivisionByZeroException

{

Print(“cannot divide by zero”);

}

Catch(error)

{

Print(“catch block:$error”);

}

Print(“End of application”);

}

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

print(num1~/num2);

double number=double.parse(pi);

print($(number*number));

}

On FormatException

{

Print(“cannot divide by zero”);

}

Catch(error)

{

Print(“catch block:$error”);

}

Print(“End of application”);

}

Output:

2

Carch block:No such Method Error :No toplevel method’$’ declared.

Receiver :top-level

End of application

40. Manually Throw Exception:

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

print(num1~/num2);

double number=double.parse(pi);

print($(number*number));

}

On FormatException

{

Print(“cannot divide by zero”);

}

Catch(error)

{

Print(“catch block:$error”);

}

Print(“End of application”);

}

Output:

2

Catch block:No such Method Error :No toplevel method’$’ declared.

Receiver :top-level

End of application

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

If(num1==100)

{

Throw new formatexception();

}

else

{

Print(num1~/num2);

On FormatException

{

Print(“Format cant be 100”);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“finally”);

}

Print(“End of application”);

}

Output:

FormatException

Finally

End of application

Description: Dart code can throw and catch exceptions. In contrast to Java, all of Dart’s exceptions are unchecked exceptions. Methods don’t declare which exceptions they might throw, and you aren’t required to catch any exceptions.

            41. CustomException- dart programming

Class EpicException implements Exception

{

Strng errMsg()=>”Epic Exception”;

}

void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

If(num1==100)

{

Throw new formatexception();

}

else

{

Print(num1~/num2);

On FormatException

{

Print(“Format cant be 100”);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“finally”);

}

Print(“End of application”);

}

Output:

Instance of ‘EpicException’

Finally

End of application

 

Description: If an unwanted condition occurs, you can throw an Exception that will be handled later. Dart already has the Exception class, but sometimes it's necessary to use custom exception class. With custom exception class, it makes us easier to use different handling for certain errors. In addition, by creating custom exceptions specific to business logic, it helps the users and the developers to understand the problem.In Dart, the custom exception class must implement Exception class. An exception usually has an error message and therefore the custom exception class should be able to return an error message.

42: Maps-Dart programming

·          void main()

{

Var epicmap={‘key1’:345,’key2:’sonu’};

Print(epicMap);

}

Output:

{‘key1’:345,’key2:’sonu’}

·         void main()

{

Var epicmap={‘key1’:345,’key2:’sonu’};

Vr epicMap = new Map();

epicMap[‘key3’]=67;

Print(epicMap);

Print(epicMap[‘key2’]);

epicMap.forEach(key,value)=>print(“$key and $value”));

}

Output:

{‘key1’:345,’key2:’sonu’}

EpicValue

Key1 and 345

Key2 and sonu                 

key3 and 67

·         void main()

{

Var epicMap = new Map();

epicMap[‘key3’]=67;

Print(epicMap);

Print(epicMap[‘key2’]);

epicMap.forEach(key,value)=>print(“$key and $value”));

}

Output:

{key3:67}

Null

Key3 and  67

Description: Defining maps is equally straight forward. Use the curly brackets { } to define a map.

                43. Lists -  dart programming

·         void main()

{

Var scores =new List(5);

scores[0] =10;

scores[1]=20;

scores[2]=30;

scores[3]=40;

scores[4]=50;

print(scores);

print(scores[1]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

}}

Output:

[10,20,30,40,50]

20

10

20

30

40

50

·         void main()

{

Var scores =new List(5);

scores[0] =10;

scores[1]=20;

scores[2]=30;

scores[3]=40;

scores[4]=50;

print(scores);

print(scores[1]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

}}

Output:

Uncaught exception:RangeError(index):Index out of range:no ndics are vakid

·         void main()

{

Var scores =new List(5);

Scores.add (10);

Scores.add(20);

Scores.add(30);

Scores.add(40);

Scores.add(50);

print(scores);

print(scores[1]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

}}

Output:

[10,20,30,40,50]

20

10

20

30

40

50

Description: Displaying lists of data is a fundamental pattern for mobile apps. Flutter includes the ListView widget to make working with lists a breeze.

          44. Enumeration –dart programming

·         Enum superheros

{

Yoda,

Batman,

Superman,

Lantern

}

Void main()

{

Print(SuperHeroes.yoda.index);

Print(SuperHeroes.Batman.index);

Print(SuperHeroes.Superman.index);

Print(SuperHeroes.Lantern.index);

}

Output:

1

2

3

4

Description: Enums are an essential part of programming languages. They help developers define a small set of predefined set of values that will be used across the logics they develop. In Dart language, which is used for developing for FlutterEnums have limited functionality.

                45.  SET –Dart programming

·         Void main()

{

Set epicset=new Set();

epicset.add(10);

epicset.add(20);

epicset.add(30);

epicset.add(40);

epicset.add(50);

print(epicset);

  print(epicset[0]);

}

Output:

{10,20,30,40,50}

Error :[] not defined

·         Void main()

{

Set epicset=new Set();

epicset.add(10);

epicset.add(20);

epicset.add(30);

epicset.add(40);

epicset.add(50);

print(epicset);

for(var value in epicset)

{

Print(value);

}

Set epicset2=new set.from([1,2,3,4,]);

Print(epicset);

}

Output:

{10,20,30,40,50}

10

20

30

40

50

{1,2,3,4}

Description:  Dart is a special case in List where all the inputs are unique i.e it doesn’t contain any repeated input. It can also be interpreted as an unordered array with unique inputs. The set comes in play when we want to store unique values in a single variable without considering the order of the inputs. The sets are declared by the use of a set keyword.

            46. HashMap –dart programming

·         Void main()

{

Var hash=new HashMap();

hash[‘key1’]=10;

hash[‘key2’]=”Hello world”;

print(hash);

print(hash[‘key2’]);

}

Output:

{key1:10,key2:Hello world}

Hello world

Description:  

The keys of a HashMap must have consistent Object.== and Object.hashCode implementations. This means that the == operator must define a stable equivalence relation on the keys (reflexive, symmetric, transitive, and consistent over time), and that hashCode must be the same for objects that are considered equal by ==.

                47.Generics –dart programming

·         Void main()

{

List <int> epicList=new List<int>();

epicList.add(1);

epicList.add(2);

epicList.add(3);

epicList.add(4);

epicList.add(5);

print(epiclist);

}

Output:

[1,2,3,4,5]

Description: Collection generics can help you be certain every element within a collection is of the expected type. It's also important to be able to trust that data that coming out of futures or streams has the right structure, and Dart's generics feature allows you to specify what that structure should be.

            48.Queue –dart programming

·         Import ‘dart:collection’;

Void main()

{

//FIFO

Queue 1 =new Queue();

q.add(10);

q.add(20);

q.add(30);

q.add(40);

q.add(50);

print(q);

q.addFirst(23);

q.addLast(90);

print(q);

}

Output:

{1,2,3,4,5}

{23,1,2,3,4,5,90}

Description: Queue is a collection that can be manipulated at both ends. One can iterate over the elements of a queue through forEach or with an Iterator. It is generally not allowed to modify the queue (add or remove entries) while an operation on the queue is being performed.

            49.Basic Class Example-Dart

·         Class vehicle

{

Int speed=60;

Void drive()

{

Print(‘drive drive “);

}}

Void main()

{

Vehicle v1=new vehicle();

Vehicle v2=new vehicle();

v1.Drive();

Print(v1.maxspeed);

v1.maxspeed=100;

Print(v1.maxspeed);

Print(v2.maxspeed);

}

Output:

Drive drive drive

60

100

60

Description: Dart has some conventions and special syntax to be aware of when designing classes and instantiating objects of those classes. There is more than one way to do almost anything, but what are the best practices in Dart? Here, we'll explore a few for class design and object instantiation.

50.Iterating over collections:

·         Void main()

{

List<int> epicList =new List<int>();

epiclist.add(1);

epiclist.add(2);

epiclist.add(3);

epiclist.add(4);

epiclist.add(5);

print(epiclist);

 

Iterator itr = epicList.iterator;

While(itr.moveNext())

{

Print(itr.current^2);

}

Output:

[1,2,3,4,5]

·         Void main()

{

List<int> epicList =new List<int>();

epiclist.add(1);

epiclist.add(2);

epiclist.add(3);

epiclist.add(4);

epiclist.add(5);

print(epiclist);

 

Iterator itr = epicList.iterator;

While(itr.moveNext())

{

Int result=itr.current;

 

Print(result*result);

}

}

Output:

[1,2,3,4,5]

1

4

9

16

25

Description: Iterate over the elements of an Iterable using the for-in loop construct, which uses the iterator getter behind the scenes. For example, you can iterate over all of the keys of a Map, because Map keys are iterable.

            51. Class Named Constructors-Dart Programming

·         Class vehicle

{

Vehicle(int speed)

{

Print(“hi”);

Maxspeed=speed;

}

Vehicle.empty

{

Print(“Named constructors”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void main()

{

Vehicle v1=new vehicle(100);

Vehicle v2=new vehicle(90);

V1.Drive();

Print(v1.maxspeed);

V1.maxspeed=89;

Print(v1.maxSpeed);

Print(v2.maxSpeed);

}

Output:

Hi

Hi

Hi

Drive drive drive

100

89

90

·         Class vehicle

{

Vehicle(int speed)

{

Print(“hi”);

Maxspeed=speed;

}

Vehicle.empty

{

Print(“Named constructors”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void main()

{

Vehicle v1=new vehicle(100);

Vehicle v2=new vehicle.empty();

V1.Drive();

Print(v1.maxspeed);

V1.maxspeed=89;

Print(v1.maxSpeed);

Print(v2.maxSpeed);

}

 

Output:

Hi

Hi

Hi

Drive drive drive

100

89

60

Description: Constructor is a special method of Dart class which is automatically called when the object is created. The constructor is like a function with/without parameter but it doesn't have a return type. Now you can create new object using a constructor.

                52. Class Constructors – Dart Programming

·         Class vehicle()

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void main()

{

Vehicle v1=new vehicle(100);

Vehicle v2=new vehicle(90);

V1.Drive();

Print(v1.maxspeed);

V1.maxspeed=89;

Print(v1.maxSpeed);

Print(v2.maxSpeed);

}

Output:

Hi

Hi

Drive drive drive

100

89

90

Description: constructor is like a function with/without parameter but it doesn't have a return type. Now you can create new object using a constructor.

53. Class Inheritance

·         Class vehicle

{

Vehicle(int speed)

{

Print(“Hi”);

_maxspeed=speed;

}

Vehicle.empty

{

Print(“Named constructors”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void set maxSped=60;

Void set maxSpeed(int speed)

{

_maxSpeed=speed*2;

}

Void get maxSpeed

{

Return _maxSpeed;

}}

Class car extends vehicle

{

Car()

{

 

Void Hello()

{

Print(“Hello,Iam a car”);

}}

Void main()

{

Car c1=new Car();

c1.Drive();

c1.maxSpeed=10;

print(c1.maxSpeed);

c1.Hello();

}

Description: This is the simplest example of a custom widget in Flutter. Note that it uses the extends keyword to indicate that the class should inherit properties and methods from StatelessWidget, which itself inherits from the Widget class.

                54.  Class custom getters and setters

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car extends vehicle

{

Car()

{

Print(“custom constructor”);

}

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Output:

Hi

Custom constructor

Drive drive drive

60

20

Hello , I’m a car

Description: Getters and setters are special methods that provide read and write access to an object’s properties. Each instance variable of your class has an implicit getter, and a setter if needed. In dart, you can take this even further by implementing your own getters and setters.

            55.Method –overriding  Dart Programs

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car extends vehicle

{

Car()

{

Print(“custom constructor”);

}

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Output:

Hi

Custom constructor

Drive drive drive

60

20

Hello , I’m a car

Description: The annotation @override marks an instance member as overriding a superclass member with the same name. The annotation applies to instance methods, getters and setters, and to instance fields, where it means that the implicit getter and setter of the field is marked as overriding, but the field itself is not.

                56.  Abstract class: -Dart programming

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Output:

Hi

Custom constructor

Drive drive drive

60

20

Hello , I’m a car

Error compiling to javascript:The non –abstract class

 ‘car’ is  missing implementation for these members:

 ‘maxSpeed’,’_maxspeed’,’maxspeed=’, ’_maxspeed=’,

Description: An Abstract class in Dart is defined for those classes which contain one or more than one abstract method (methods without implementation) in them. Whereas, to declare abstract class we make use of the abstract keyword. So, it must be noted that a class declared abstract may or may not include abstract methods but if it includes an abstract method then it must be an abstract class.

                57. This Keyword – Dart Programming

·          Void main()

{

 Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

this._maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Void main()

{

Car c1=new car();

C1.Drive();

Print(c1.maxspeed);

C1.maxspeed=10;

Print(c1.maxspeed);

C1.Hello();

}

Output:

Hi

Custom constructor

New drive

60

20

Hello, Iam a car

            Description: this keyword represents an implicit object pointing to the current class object. It refers to the current instance of the class in a method or constructor. The this keyword is mainly used to eliminate the ambiguity between class attributes and parameters with the same name. When the class attributes and the parameter names are the same this keyword is used to avoid ambiguity by prefixing class attributes with this keyword.

            58. Multiple class Inheritance

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Class bmw extends car

{

Void hey()

{

Print(“Grandchild class”);

}}

Void main()

{

BMW b1=new BMW();

b1.Hey();

b1.Drive();

}

Output:

Hi

 Custom constructor

Grandchild class

New Drive

Description: Multiple Inheritance: When a class inherits more than one parent class than this inheritance occurs. Dart doesn't support this. 

            59. Super keyword –dart programming

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

@override

Void Drive()

{

super.Drive();

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Void main()

{

BMW b1=new BMW();

b1.Hey();

b1.Drive();

}

 

Output:

Hi

Custom constructor

Drive drive drive

New Drive

60

10

Hello, Iam a car

Description: super is used to call the constructor of the base class. So in your example, the constructor of CardTitle is calling the constructor of StatelessWidget .

            60.  Static Keyword –dart programming

Abstract Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

static int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Void main()

{

Car c1=new car();

Ca1.Drive();

Print(Car.maxspeed);

Car.maxspeed=10;

Print(Car.maxspeed);

C1.Hello();

 

Car c2= new Car();

Print(car.maxSpeed);

}

Output:

Hi

Custom constructor

New drive

60

10

Hello, Iam a car

Hi

Custom constructor

10

                Description: The static keyword is used for a class-level variable and method that is the same for every instance of a class, this means if a data member is static, it can be accessed without creating an object. The static keyword allows data members to persist Values between different instances of a class.

            61. Debugging-dart programming

·         void main()

{

Int  x=10;

Int  y=20;

Y=90;

Print(x*y);

}

Output:

900

Process finished with exit code 0

Description:   This doc describes debugging features that you can enable in code. For a full list of debugging and profiling tools, see the Debugging page.

            62.  Runes – Dart Programming

·         void main()

{

String epicString=”Helo world”;

Print(epicString.codeUnits);

Print(epicString.codeUnitAt(1));

}

Output:

[72,101,108,111,32,87,11,114,108,100]

101

Description: rune is an integer representing a Unicode code point.

The String class in the dart:core library provides mechanisms to access runes. String code units / runes can be accessed in three ways

·         Using String.codeUnitAt() function

·         Using String.codeUnits property

·         Using String.runes property

 

            63.TypeDef operator  -Dart programming

·         typedef operator(int num1,int num2);

Addition(int num1,int num2)

{

Print(num1+num2);

}

Substraction(int num1,int num2)

{

Print(num1-num2);

}

Multiplication(int num1,int num2)

{

Print(num1*num2);

}

Division(int num1,int num2)

{

Print(num1/num2);

}

Calculation(int num1,int num2,Operator opAlias)

{

opAlias(num1,num20;

}

Void main()

{

Addition(10,5);

Substraction(10,5);

Multiplication(10,5);

Division(10,5);

}

Output:

15

5

50

2

·         typedef operator(int num1,int num2);

Addition(int num1,int num2)

{

Print(num1+num2);

}

Substraction(int num1,int num2)

{

Print(num1-num2);

}

Multiplication(int num1,int num2)

{

Print(num1*num2);

}

Division(int num1,int num2)

{

Print(num1/num2);

}

Calculation(int num1,int num2,Operator opAlias)

{

opAlias(num1,num20;

}

Void main()

{

Addition(10,5);

Substraction(10,5);

Multiplication(10,5);

Division(10,5);

Operator op=Addition;

Op(90,80);

Op=multiplication;

Op(10,8);

}

Output:

170

80

Description: Typedef in Dart is used to create a user-defined identity (alias) for a function, and we can use that identity in place of the function in the program code.

 

 

 

            64. Libraries – Dart programming

·         void main()

{

int  i=5;

print(i*i);

print(i^2)

}

Output:

25

7

·         library custom_lib;

import ‘dart:math’;

void main()

{

I=9;

Print(sqrt(i));

}

Output:

3

Description: Libraries contain ancillary code and data, which provides standalone program services, allowing for the modular sharing and modification of code and data 

            65.  Concurrency – Dart Programming

·         import  ‘dart:isolate’;

void Func(String  str)

{

Print(str);

}

Void main()

{

Isolate.spawn(Func,”1”);

Isolate.spawn(Func,”2”);

Isolate.spawn(Func,”3”);

Isolate.spawn(Func,”4”);

Isolate.spawn(Func,”5”);

Isolate.spawn(Func,”6”);

Print(“Normal 1”);

Print(“Normal 2”);

Print(“Normal 3”);

Print(“Normal 4”);

Print(“Normal 5”);

Print(“Normal 6”);

}

Output:

Normal  1

Normal 2

Normal 3

Normal 4

Normal 5

Normal 6

5

3

1

6

2

Process finished exit 0

            Description: Flutter/Dart is NOT single-threaded; Dart’s concurrency model is NOT Java’s thread; Future/Async/Await runs on the same thread and solves IO-bound problems, while Dart’s Isolate/Flutter’s compute runs on a different isolated (no-shared-memory) thread and solves CPU-bound ones.

 

 

 

1.      Printing to the console in Dart programming

Void main()

{                                                                                                     

print(“Heloo world”);

print(“Batman”);

print(“Batman”);

print(“Batman”);

print(“Batman”);

print(“Batman”);

}

Output:

Heloo world

Batman

Batman

Batman

Batman

Batman

Description: when used in console based application it outputs in the terminal console.

2.       Comments -dart programming

//     Singleline comment

/* */   Multiline comment

Description: Just put two slash symbols at the beginning of the line you want to comment out. //This is a comment.(single line Comment), his method is usually used to comment out a block of code.(multiline comment).

3.       Print Variables Inside  to a String

·         Void main()

{

var  x=10;

var y=”Hello world”;

print(x);

print(y);

}

Output:

10

Hello world

·         Void Main()

{

Var  age=18;

Var  food=”pizza”;

Print(“Iam $age and I love eating $food”);

}

Output:

Iam 18 and I love eating pizza

·         Void main()

{

Var  age =90;

Var  food=”Pizza$age”;

Print(“Iam $age and I love eating $food”);

Print(food);

}

Output:

Iam 90 and I love eating pizza 90

Pizza 90

            Description: Variables used to print the value of the int along with the string.

4.      Console  Input – Dart programming

·         import  ‘dart:io’;

void main()

{

String str=stdin.readLineSync(); //Input should be given in console

Print(str);

Print(“End of  application”);

}

Output:

 Hello

Hello

End of application

                Description: The readLineSync() method of stdin allows to capture a String from the console

5.       Variables – Dart Programming

·         Void man()

{

Var epicName;

epicName=”Hello world”; or  var epicName=”Hello world”;

print(epicName);

}

Output:

HelloWorld

 

·         Void main()

{

String  epicName=”Hello world”;

epicName=89;

print(epicName);

}

Output:

Error compiling to javascript: Error: A value of type ‘dart.core::int’ can’t be assigned to a variable of type, ‘dart.core::string’.epicName=89;

·         Void main()

{

int epicName=90;

epicName=89;

print(epicName);

}

Output;

89

·         Void main()

{

Var epicName=”Hello world”;

epicName=”Batman”;

print(epicName);

}

Output:

Batmen

·         Void main()

{

Var epicName=90;

epicName=80;

print(epicName);

}

Output:

80

Description:  use the var keyword to define variables. once assigned a type is assigned you    can’t reassign a value with new type to the variable. Dart automatically infers the type of data from the right hand side.You can also define variables by explicitly providing type of data.

6.      Final and constant Variables – Dart programming

·         Void main()

{

Final var  v1=9;

Const var  v2=10;

V1=8;

V2=2;

Print(v1);

Print(v2);

}

Output:

Error:Setter not found:’v2’.

·         Voidmain(){

Const pi=3.1456;

final v1=9;const v2=10;

print(v1);print(v2);}

 output:Error

·         Int Epic()

{

Return 1;

}

Void main()

{

final v1=Epic();

const v2=89;

print (v1);

print(v2);

}}

Output:

1

                89

Description: const variables must have a value during compile time, for example  const PI = 3.14; , whereas variables that are final can only be assigned once, they need not be assigned during compile time and can be assigned during runtime.

7.       Static vs Dynamic Variables – Dart Programming

·         Class Epic

{

Var satus=0;

Static var statics=0;

epicFun()

{

Status++;

Statics++;

Print(‘status:$status & statics:$statics’);

}}

 

·         Void main()

{

Print(“E1”);

Epic e=new Epic();

e.epicFun();

e.epicFun();

e.EpicFun();

Print(“E2”);

Epic e2=new Epic();

e2.epicFun();

e2.epicFun();

e2.EpicFun();

}

Output:

E1

status:1 & statics:1

status:2 & statics:2

status:3 & statics:3

E2

status:1 & statics:4

status:2 & statics:5

status:3 & statics:6

Description: Dynamic you can access the methods and properties of it's type. But static doesn't allow to access it.

8.      DataTypes- Dart programming

·         Void main()

{

Int i=4;

Print(i);

Double d=9.5;

Print(d);

String s=”Hello world”;

Print(s);

bool  b =true;

print(b);

}

Output:

4

9.5

Hello world

True

Description:  basic data types that you can expect from a modern language.

  • Numbers
  • Strings
  • Booleans

9.      Boolean –Dart programming

·         Void main()

{

bool  var1;

Var2=67>89;

Print(var1);

}

Output:

False

·         Void main()

{

bool  var1;

Var2=67>89;

Print(var1);

}

                Output:

                True

Description: Boolean has trueb or false parameters,

10.  Numbers –Dart Programming

·         Void main()

{

String str =”5”;

int  i=num.parse(str);

print(i);

double d=9.5;

print(d);

}

Output:

5

9.5

·         Void main()

{

String str=”-5”;

int  i=num.parse(str);

print(i);

double d=num.parse(“6.78”);

print(d);

 print(d.round());

print(d.truncate());

print(i.isNegative);

Output:

-5

6.78

7

6

True

Description: Number is one of datatype contains int ,double,negative,round and truncate.

11.  Arithmetic  Operators

·         Void main()

{

int num1=10;

int num2=5;

print(num1+num2);//addition

print(num1-num2);//substraction

print(num1*num2);//multiplication

print(num1/num2);// division

print(num~/num2);//integer division

print(num1%num2);//modulous 0

print(-num1); -10             //if num1 is -10 output is 10

//increment ++

Print(num1);//10

Num1++;

Print(num1);//11

                //decrement –

Print(num2);//5

Num2--;

Print(num2);//4

int numExtra=8;

print(numExtra++);//8

print(numExtra);//9

 

int numExtra=8 ;

print(++numExtra);//9

print(numExtra);//9

}

Output:

15

5

50

2

2

0

-10

 10

11

5

4

Description:Arithmetic operators included +,-,*,/,^,&. An expression is a special kind of statement that evaluates to a value. Every expression is composed of −

·        Operands − Represents the data

·        Operator − Defines how the operands will be processed to produce a value.

Consider the following expression – "2 + 3". In this expression, 2 and 3 are operands and the symbol "+" (plus) is the operator.

 

12.  Strings – Dart Programming

·         Void main()

{

String str=”Hello world”;

print(str);

String str2=’You\’re’;

print(str2);

String str2=”You’re”;

print(str2);

 

String str3=”””Hello world”””;

print(str3);

String str4=’’’Hello Hi world’’’;

print(str4 );

}

Output:

Hello world

You’re

Hello

      World

Hello

     Hi

     World

·         Void main()

{

String name=”Batman”;

String str1=”Hello ”;

String str2=”wo${name}rld”;

String result=str1+str2;

Print(result);

}

Output:

Hello WoBatmanrld

·         Void main()

{

String name=”Batman”;

String str1=”    Hello    ”;

String str2=”wo${6*6}rl$(name)d”;

String result=str1+str2;

Print(result);

Print(str1.length);

Print(str1.toLowerCase());

Print(str1.toUpperCase());

Print(str1.trim());

}

Output:

      Hello    Wo36Batmanrld

12

       hello

       HELLO

Hello

Description: A string can be either single or multiline. Single line strings are written using matching single or double quotes, and multiline strings are written using triple quotes.

13.  Relational Operators –Dart Programming

·         Void main()

{

Int num1=5;

Int num2=5;

Print(num1>num2);GT

Print(num1<num2);LT

Print(num1>=num2);GE

Print(num1<=num2);LE

Print(num==num2); EqualTo

Print(num!-num2);not equalto

Output:

False

False

True

True

True

False

Description: Dart operators are as follows:

·         ==: For checking whether operands are equal

·         !=: For checking whether operands are different

For relational tests, the operators are as follows:

·         >: For checking whether the left operand is greater than the right one

·         <: For checking whether the left operand is less than the right one

·         >=: For checking whether the left operand is greater than or equal to the right one

·         <=: For checking whether the left operand is less than or equal to the right one.

14.  Type Test Operators

·         Void main()

{

int  i=10;

Print(i  is! String);//Is Type

Print(i  is! String);//is not type

}

Output:

False

True

Description: The Type test operators are used to check type of an object. These operators are handy for checking types at runtime.

15.  Logical Operators

·         Void main()

{

Int num1=10;

Int num2=5;

Print(num1>num2 && num1<20);// And operator

Print(num1>num2 || num1<20);//OR operator

Print(!(num1>num2));//NOT!

}

Output:

False

True      false

Description: Short-circuit Operators (&& and ||) The && and || operators are used to combine expressions. The && operator returns true only when both the conditions return true.

16.  Assignment operator

·         Void main()

{

int  i=20;

int  j=7;

j ??=10;

print(j);         //7

int num1=10;

print(num1);//10

num1 +=5;                //num1=num1+5;

print(num1);   //15

//substract

int num2=10;

print(num2);//10

num2 -=5;                //num2=num2-5;

print(num2);   //5

//multiply

int num3=10;

print(num3);//10

num3 *=5;                //num2=num3*5;

num3 *=5;               //250

print(num3);   //50

//Divide

double num4=10;

print(num4);

num4 /=5;                //num2=num2/5;

print(num4);   //2

}

Output:

7  

10

15

 10

 5

 10

 50

 10

 2

Description: Assignment operators are used in flutter to assign right side operand value to left side operand. The basic assignment operator in flutter is =(Equal). Equal is assign right side value to left side operand without any modification.

17.  Conditional Expressions

·         Void main()

{

Int num1=980;

Var result=num1<100? ”It is less than 100” : “It is more than 100”;

Print(result);

Int num2=null;

Var result2=num2??”It is null”;

int num3=7;

Var result2=num3??”It is null”;

Print(result2);

}

Output:

It is more than 100

It is null

7

Description: The ternary operator is technically that: an operator. But, it's also kind of an if/else substitute. It's also kind of a ?? alternative, depending on the situation. The ternary expression is used to conditionally assign a value. It's called ternary because it has three portions: the condition, the value if the condition is true, and the value if the condition is false.

18.  Bitwise Operators

·         Void main()

{

Int num1=55;

Int num2=78;

Print(num1&num2)//bitwise and&    6

Print(num1|num2)//bitwise Or|      127

Print(num1^num2)//bitwise Xor^     121

Print(~num2);      4294967217   

Print(num1<3);    false ;

}

Description: You can manipulate the individual bits of numbers in Dart. Usually, you'd use these bitwise and shift operators with integers.    

19.  Conditional IF statement

·         Void main()

{

int num1=100;

if(num1==0)

{

Print(“it is 0”);

}

else if(num1==10)

{

Print(“it is 10”);

}

 

else if(num1>=50)

{

Print(“Greater than 50”);//100 greater than 50

}

else

{

Print(“Default”); 45 lesser than 50 its default

}

}

Description: In normal If condition there are two parts If part and Else part. If the given condition is True then it will execute the If body part statements. If the given condition is False then it will automatically execute the Else part. 

20.  Switch statement – Dart programming

·         Void main()

{

  Int x=8;

Switch(x)

{

Case 0:print(“0”);

Break;

 

Case 1:print(“1”);

Break;

Case 2:print(“2”);

Break;

Case 3:print(“3”);

Break;

Default:print(“default”);

Break;

}}

Output:

8

Description: The switch statement evaluates an expression, matches the expression’s value to a  case clause and executes the statements associated with that case.

21.  For in loop

·         Void main()

{

Var i=[1,2,3,4,67,89,0];

for(  var val in i)

{

Print(val);

}}

Outpuyt:

1

2

3

4

67

89

0

Description: Dart for in loop is also a loop but a bit different than conventional for loop. It is mainly used to iterate over array’s or collection’s elements. The advantage for in loop has over the conventional for loop is clean code means fewer chances of error and more productivity. 

22.  For loop

·         Void main()

{

For(int i=0;i<=10;i++)

{

Print(i); 1 to 10

Print(i*i);   1 4 9 19 25 36 49………………………………..

}}

Output:

1 4 9 19 25 36 49……………………………….

Description:Use for loop directly inside a Column/ListView's children. . It is mainly used to iterate over array’s or collection’s elements.

23.  While loop

·         Void main()

{

Int i=0;

While(i<=100)

{

Print(i*i);

i++;

}}

Output:

1 4 9 25 36……………………100000

Description: while loop executes its code block as long as the condition is true. The functionality of while loop is very similar to for loop but in while loop first the condition is verified then while loop code block is executed and later on incremental/ decremental variable value is changed to control the flow of while loop.

24.  Do while

·         Void main()

{

Int i=0;

While(i<=100)

{

Print(i*i);

i++;

}

int x=10;

do

{

Print(x*x);

i++;

}

While(i<=5);

}

Output:

0

1

4

9

16

25

0

1

4

9

16

25

·         Void main()

{

int x=10;

do

{

Print(x*x);

i++;

}

While(x<=5);

}

Output:

100

Description: Do…while loop is similar to the while loop except that the do...while loop doesn’t evaluate the condition for the first time the loop executes. However, the condition is evaluated for the subsequent iterations. In other words, the code block will be executed at least once in a do…while loop.

25.  Break statement

·         Void main()

{

for(int i=0;i<=5;i++)

{

If(i==3)

{

Print(“Before break”);

Break;

Print(“after break”);

}

Print(i*i);

}

Print(“outside of loop”);}

Output:

0

1

4

Before break

outside loop

Description: The break statement is used to take the control out of a construct. Using break in a loop causes the program to exit the loop.

27.Continue statement

·         Void main()

{

for(int i=0;i<=5;i++)

{

If(i==3) //skip 3 and continue from 4

{

Print(“Before break”);

continue;

Print(“after break”);

}

Print(i*i);

}

Print(“outside of loop”);}

Output:

0

1

4

Before break

16

25

Outside of loop

Description: The continue statement skips the subsequent statements in the current iteration and takes the control back to the beginning of the loop. Unlike the break statement, the continue statement doesn’t exit the loop. It terminates the current iteration and starts the subsequent iteration.

   28. Basic Function:

·         void main()

{

Epic();

}

Void  Epic()

{Print(“Hello world”);}

Output:

Hello world

Description: Dart language is the base of Flutter. Hence creating functions in Flutter is the same as creating functions in Dart. In this blog post, let’s check how to create and use functions in Flutter. I hope it will be helpful for those who are new to Flutter.

29. Function Parameters

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99,0);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

}

Output:

12

-7

99

Description: Functions can have two types of parameters: required and optional. The required parameters are taking the front row, followed by any optional parameters.

        30.Functional optional named parameter

·         Void main()

{

Add(num2:5,  

num1:8,

num3:7);

}

Void Add(int num1,{int num2,int num3})

{

Print(num1);

print(num2);

print(num3);

}

Output:

8

5

Description:

31. Function Optional Positional parameters

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99,0);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

} 

Output:

12

-7

99

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

} 

Output:

12

-7

Uncaught exception:

Invalid argument:null

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99);

}

Void Add(int num1,[int num2])

{

Print(num1);

Print(num2);

}

Ouput:

5

7

-9

2

99

Null

32.Function Return values

·         Void main()

{

Add(10,9);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

}

Output:

19

·         Void main()

{

int result=Add(10,9);

print(result);

print(result*result);

}

int Add(int num1,int num2)

{

return num1+num2;

}

Output:

19

361

Output: Functions in Dart are as simple as it can get, somewhat similar to javascript. All you need to do is provide a name, a return type and parameters.

33. Function Recursion

·         Void main()

{

Int res=calculateFactorial(6);

Print(res);

}

Int calculateFactorial(int n)

{

Print(“Hello”);

If(n<=0)

{

return 1;

}

else

{

Int result=(n*calculateFactorial(n-1));

return result;

}}

Output:

Hello

Hello

Hello

Hello

Hello

Hello

2

·         Void main()

{

Int res=calculateFactorial(15);

Print(res);

}

Int calculateFactorial(int n)

{

Print(“Hello”);

If(n<=0)

{

return 1;

}

else

{

Int result=(n*calculateFactorial(n-1));

return result;

}}

Output:

1307674368000

Description: Dart Recursion is the method where a function calls itself as its subroutine. It is used to solve the complex problem by dividing it into sub-part. A function which is called itself again and again or recursively, then this process is called recursion.

35. Lamda Function –Dart programming

·         Void main()

{

Epic();

}

Epic()=>print(“we are epic”);

String EpicReturn()=>”Hi”;

Output:

We are epic

Hi

Description: Lambda functions are also called Arrow functions. But here remember that by using Lambda function's syntax you can only return one expression. It must be only one line expression. Just like normal function lambda function cannot have a block of code to execute.

36. Try on block –Dart programming

·         Void main()

{

Int num1=10;

Int num2=6;

try{

print(num~/num2);

}

Catch(error)

{

Print(error);

}

 Print(“End of application”);

}

Output:

1

End of application

·         Void main()

{

Int num1=10;

Int num2=6;

try{

print(num~/num2);

}

On IntegerDivisionByZeroException

{

Print(“create divide by zero”);

}

 Print(“End of application”);

}

Description: The try block embeds code that might possibly result in an exception. The on block is used when the exception type needs to be specified. The catch block is used when the handler needs the exception object. The try block must be followed by either exactly one on / catch block or one finally block

37. Try catch block- Dart programming

·         void main()

{

Int num1=10;

Int num2=0;

Print(num1~/num2);

try

{

Print(num~/num2);

}

Catch(error)

{

Print(error);

}

Print(“End of application”);

}

Description: The try block embeds code that might possibly result in an exception. The on block is used when the exception type needs to be specified. The catch block is used when the handler needs the exception object. The try block must be followed by either exactly one on / catch block or one finally block.

38. Finally Block –Dart programming

·         void main()

{

Int num1=10;

Int num2=5;

Print(num1~/num2);

try

{

Print(num~/num2);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“Finally”);

}

Print(“End of application”);

}

·         void main()

{

Int num1=10;

Int num2=0;

Print(num1~/num2);

try

{

Print(num~/num2);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“Finally”);

}

Print(“End of application”);

}

Output:

Unsupported operation:Result of truncating

Division is infinity:10~/0

Finally

End of application

            Description: The finally block includes code that should be executed irrespective of an exception's occurrence. The optional finally block executes unconditionally after try/on/catch.

39. Try on catch block –Dart programming

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

print(num1~/num2);

double number=double.parse(pi);

print(number*number);

}

On IntegerDivisionByZeroException

{

Print(“cannot divide by zero”);

}

Catch(error)

{

Print(“catch block:$error”);

}

Print(“End of application”);

}

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

print(num1~/num2);

double number=double.parse(pi);

print($(number*number));

}

On FormatException

{

Print(“cannot divide by zero”);

}

Catch(error)

{

Print(“catch block:$error”);

}

Print(“End of application”);

}

Output:

2

Carch block:No such Method Error :No toplevel method’$’ declared.

Receiver :top-level

End of application

40. Manually Throw Exception:

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

print(num1~/num2);

double number=double.parse(pi);

print($(number*number));

}

On FormatException

{

Print(“cannot divide by zero”);

}

Catch(error)

{

Print(“catch block:$error”);

}

Print(“End of application”);

}

Output:

2

Catch block:No such Method Error :No toplevel method’$’ declared.

Receiver :top-level

End of application

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

If(num1==100)

{

Throw new formatexception();

}

else

{

Print(num1~/num2);

On FormatException

{

Print(“Format cant be 100”);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“finally”);

}

Print(“End of application”);

}

Output:

FormatException

Finally

End of application

Description: Dart code can throw and catch exceptions. In contrast to Java, all of Dart’s exceptions are unchecked exceptions. Methods don’t declare which exceptions they might throw, and you aren’t required to catch any exceptions.

            41. CustomException- dart programming

Class EpicException implements Exception

{

Strng errMsg()=>”Epic Exception”;

}

void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

If(num1==100)

{

Throw new formatexception();

}

else

{

Print(num1~/num2);

On FormatException

{

Print(“Format cant be 100”);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“finally”);

}

Print(“End of application”);

}

Output:

Instance of ‘EpicException’

Finally

End of application

 

Description: If an unwanted condition occurs, you can throw an Exception that will be handled later. Dart already has the Exception class, but sometimes it's necessary to use custom exception class. With custom exception class, it makes us easier to use different handling for certain errors. In addition, by creating custom exceptions specific to business logic, it helps the users and the developers to understand the problem.In Dart, the custom exception class must implement Exception class. An exception usually has an error message and therefore the custom exception class should be able to return an error message.

42: Maps-Dart programming

·          void main()

{

Var epicmap={‘key1’:345,’key2:’sonu’};

Print(epicMap);

}

Output:

{‘key1’:345,’key2:’sonu’}

·         void main()

{

Var epicmap={‘key1’:345,’key2:’sonu’};

Vr epicMap = new Map();

epicMap[‘key3’]=67;

Print(epicMap);

Print(epicMap[‘key2’]);

epicMap.forEach(key,value)=>print(“$key and $value”));

}

Output:

{‘key1’:345,’key2:’sonu’}

EpicValue

Key1 and 345

Key2 and sonu                 

key3 and 67

·         void main()

{

Var epicMap = new Map();

epicMap[‘key3’]=67;

Print(epicMap);

Print(epicMap[‘key2’]);

epicMap.forEach(key,value)=>print(“$key and $value”));

}

Output:

{key3:67}

Null

Key3 and  67

Description: Defining maps is equally straight forward. Use the curly brackets { } to define a map.

                43. Lists -  dart programming

·         void main()

{

Var scores =new List(5);

scores[0] =10;

scores[1]=20;

scores[2]=30;

scores[3]=40;

scores[4]=50;

print(scores);

print(scores[1]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

}}

Output:

[10,20,30,40,50]

20

10

20

30

40

50

·         void main()

{

Var scores =new List(5);

scores[0] =10;

scores[1]=20;

scores[2]=30;

scores[3]=40;

scores[4]=50;

print(scores);

print(scores[1]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

}}

Output:

Uncaught exception:RangeError(index):Index out of range:no ndics are vakid

·         void main()

{

Var scores =new List(5);

Scores.add (10);

Scores.add(20);

Scores.add(30);

Scores.add(40);

Scores.add(50);

print(scores);

print(scores[1]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

}}

Output:

[10,20,30,40,50]

20

10

20

30

40

50

Description: Displaying lists of data is a fundamental pattern for mobile apps. Flutter includes the ListView widget to make working with lists a breeze.

          44. Enumeration –dart programming

·         Enum superheros

{

Yoda,

Batman,

Superman,

Lantern

}

Void main()

{

Print(SuperHeroes.yoda.index);

Print(SuperHeroes.Batman.index);

Print(SuperHeroes.Superman.index);

Print(SuperHeroes.Lantern.index);

}

Output:

1

2

3

4

Description: Enums are an essential part of programming languages. They help developers define a small set of predefined set of values that will be used across the logics they develop. In Dart language, which is used for developing for FlutterEnums have limited functionality.

                45.  SET –Dart programming

·         Void main()

{

Set epicset=new Set();

epicset.add(10);

epicset.add(20);

epicset.add(30);

epicset.add(40);

epicset.add(50);

print(epicset);

  print(epicset[0]);

}

Output:

{10,20,30,40,50}

Error :[] not defined

·         Void main()

{

Set epicset=new Set();

epicset.add(10);

epicset.add(20);

epicset.add(30);

epicset.add(40);

epicset.add(50);

print(epicset);

for(var value in epicset)

{

Print(value);

}

Set epicset2=new set.from([1,2,3,4,]);

Print(epicset);

}

Output:

{10,20,30,40,50}

10

20

30

40

50

{1,2,3,4}

Description:  Dart is a special case in List where all the inputs are unique i.e it doesn’t contain any repeated input. It can also be interpreted as an unordered array with unique inputs. The set comes in play when we want to store unique values in a single variable without considering the order of the inputs. The sets are declared by the use of a set keyword.

            46. HashMap –dart programming

·         Void main()

{

Var hash=new HashMap();

hash[‘key1’]=10;

hash[‘key2’]=”Hello world”;

print(hash);

print(hash[‘key2’]);

}

Output:

{key1:10,key2:Hello world}

Hello world

Description:  

The keys of a HashMap must have consistent Object.== and Object.hashCode implementations. This means that the == operator must define a stable equivalence relation on the keys (reflexive, symmetric, transitive, and consistent over time), and that hashCode must be the same for objects that are considered equal by ==.

                47.Generics –dart programming

·         Void main()

{

List <int> epicList=new List<int>();

epicList.add(1);

epicList.add(2);

epicList.add(3);

epicList.add(4);

epicList.add(5);

print(epiclist);

}

Output:

[1,2,3,4,5]

Description: Collection generics can help you be certain every element within a collection is of the expected type. It's also important to be able to trust that data that coming out of futures or streams has the right structure, and Dart's generics feature allows you to specify what that structure should be.

            48.Queue –dart programming

·         Import ‘dart:collection’;

Void main()

{

//FIFO

Queue 1 =new Queue();

q.add(10);

q.add(20);

q.add(30);

q.add(40);

q.add(50);

print(q);

q.addFirst(23);

q.addLast(90);

print(q);

}

Output:

{1,2,3,4,5}

{23,1,2,3,4,5,90}

Description: Queue is a collection that can be manipulated at both ends. One can iterate over the elements of a queue through forEach or with an Iterator. It is generally not allowed to modify the queue (add or remove entries) while an operation on the queue is being performed.

            49.Basic Class Example-Dart

·         Class vehicle

{

Int speed=60;

Void drive()

{

Print(‘drive drive “);

}}

Void main()

{

Vehicle v1=new vehicle();

Vehicle v2=new vehicle();

v1.Drive();

Print(v1.maxspeed);

v1.maxspeed=100;

Print(v1.maxspeed);

Print(v2.maxspeed);

}

Output:

Drive drive drive

60

100

60

Description: Dart has some conventions and special syntax to be aware of when designing classes and instantiating objects of those classes. There is more than one way to do almost anything, but what are the best practices in Dart? Here, we'll explore a few for class design and object instantiation.

50.Iterating over collections:

·         Void main()

{

List<int> epicList =new List<int>();

epiclist.add(1);

epiclist.add(2);

epiclist.add(3);

epiclist.add(4);

epiclist.add(5);

print(epiclist);

 

Iterator itr = epicList.iterator;

While(itr.moveNext())

{

Print(itr.current^2);

}

Output:

[1,2,3,4,5]

·         Void main()

{

List<int> epicList =new List<int>();

epiclist.add(1);

epiclist.add(2);

epiclist.add(3);

epiclist.add(4);

epiclist.add(5);

print(epiclist);

 

Iterator itr = epicList.iterator;

While(itr.moveNext())

{

Int result=itr.current;

 

Print(result*result);

}

}

Output:

[1,2,3,4,5]

1

4

9

16

25

Description: Iterate over the elements of an Iterable using the for-in loop construct, which uses the iterator getter behind the scenes. For example, you can iterate over all of the keys of a Map, because Map keys are iterable.

            51. Class Named Constructors-Dart Programming

·         Class vehicle

{

Vehicle(int speed)

{

Print(“hi”);

Maxspeed=speed;

}

Vehicle.empty

{

Print(“Named constructors”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void main()

{

Vehicle v1=new vehicle(100);

Vehicle v2=new vehicle(90);

V1.Drive();

Print(v1.maxspeed);

V1.maxspeed=89;

Print(v1.maxSpeed);

Print(v2.maxSpeed);

}

Output:

Hi

Hi

Hi

Drive drive drive

100

89

90

·         Class vehicle

{

Vehicle(int speed)

{

Print(“hi”);

Maxspeed=speed;

}

Vehicle.empty

{

Print(“Named constructors”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void main()

{

Vehicle v1=new vehicle(100);

Vehicle v2=new vehicle.empty();

V1.Drive();

Print(v1.maxspeed);

V1.maxspeed=89;

Print(v1.maxSpeed);

Print(v2.maxSpeed);

}

 

Output:

Hi

Hi

Hi

Drive drive drive

100

89

60

Description: Constructor is a special method of Dart class which is automatically called when the object is created. The constructor is like a function with/without parameter but it doesn't have a return type. Now you can create new object using a constructor.

                52. Class Constructors – Dart Programming

·         Class vehicle()

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void main()

{

Vehicle v1=new vehicle(100);

Vehicle v2=new vehicle(90);

V1.Drive();

Print(v1.maxspeed);

V1.maxspeed=89;

Print(v1.maxSpeed);

Print(v2.maxSpeed);

}

Output:

Hi

Hi

Drive drive drive

100

89

90

Description: constructor is like a function with/without parameter but it doesn't have a return type. Now you can create new object using a constructor.

53. Class Inheritance

·         Class vehicle

{

Vehicle(int speed)

{

Print(“Hi”);

_maxspeed=speed;

}

Vehicle.empty

{

Print(“Named constructors”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void set maxSped=60;

Void set maxSpeed(int speed)

{

_maxSpeed=speed*2;

}

Void get maxSpeed

{

Return _maxSpeed;

}}

Class car extends vehicle

{

Car()

{

 

Void Hello()

{

Print(“Hello,Iam a car”);

}}

Void main()

{

Car c1=new Car();

c1.Drive();

c1.maxSpeed=10;

print(c1.maxSpeed);

c1.Hello();

}

Description: This is the simplest example of a custom widget in Flutter. Note that it uses the extends keyword to indicate that the class should inherit properties and methods from StatelessWidget, which itself inherits from the Widget class.

                54.  Class custom getters and setters

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car extends vehicle

{

Car()

{

Print(“custom constructor”);

}

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Output:

Hi

Custom constructor

Drive drive drive

60

20

Hello , I’m a car

Description: Getters and setters are special methods that provide read and write access to an object’s properties. Each instance variable of your class has an implicit getter, and a setter if needed. In dart, you can take this even further by implementing your own getters and setters.

            55.Method –overriding  Dart Programs

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car extends vehicle

{

Car()

{

Print(“custom constructor”);

}

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Output:

Hi

Custom constructor

Drive drive drive

60

20

Hello , I’m a car

Description: The annotation @override marks an instance member as overriding a superclass member with the same name. The annotation applies to instance methods, getters and setters, and to instance fields, where it means that the implicit getter and setter of the field is marked as overriding, but the field itself is not.

                56.  Abstract class: -Dart programming

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Output:

Hi

Custom constructor

Drive drive drive

60

20

Hello , I’m a car

Error compiling to javascript:The non –abstract class

 ‘car’ is  missing implementation for these members:

 ‘maxSpeed’,’_maxspeed’,’maxspeed=’, ’_maxspeed=’,

Description: An Abstract class in Dart is defined for those classes which contain one or more than one abstract method (methods without implementation) in them. Whereas, to declare abstract class we make use of the abstract keyword. So, it must be noted that a class declared abstract may or may not include abstract methods but if it includes an abstract method then it must be an abstract class.

                57. This Keyword – Dart Programming

·          Void main()

{

 Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

this._maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Void main()

{

Car c1=new car();

C1.Drive();

Print(c1.maxspeed);

C1.maxspeed=10;

Print(c1.maxspeed);

C1.Hello();

}

Output:

Hi

Custom constructor

New drive

60

20

Hello, Iam a car

            Description: this keyword represents an implicit object pointing to the current class object. It refers to the current instance of the class in a method or constructor. The this keyword is mainly used to eliminate the ambiguity between class attributes and parameters with the same name. When the class attributes and the parameter names are the same this keyword is used to avoid ambiguity by prefixing class attributes with this keyword.

            58. Multiple class Inheritance

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Class bmw extends car

{

Void hey()

{

Print(“Grandchild class”);

}}

Void main()

{

BMW b1=new BMW();

b1.Hey();

b1.Drive();

}

Output:

Hi

 Custom constructor

Grandchild class

New Drive

Description: Multiple Inheritance: When a class inherits more than one parent class than this inheritance occurs. Dart doesn't support this. 

            59. Super keyword –dart programming

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

@override

Void Drive()

{

super.Drive();

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Void main()

{

BMW b1=new BMW();

b1.Hey();

b1.Drive();

}

 

Output:

Hi

Custom constructor

Drive drive drive

New Drive

60

10

Hello, Iam a car

Description: super is used to call the constructor of the base class. So in your example, the constructor of CardTitle is calling the constructor of StatelessWidget .

            60.  Static Keyword –dart programming

Abstract Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

static int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Void main()

{

Car c1=new car();

Ca1.Drive();

Print(Car.maxspeed);

Car.maxspeed=10;

Print(Car.maxspeed);

C1.Hello();

 

Car c2= new Car();

Print(car.maxSpeed);

}

Output:

Hi

Custom constructor

New drive

60

10

Hello, Iam a car

Hi

Custom constructor

10

                Description: The static keyword is used for a class-level variable and method that is the same for every instance of a class, this means if a data member is static, it can be accessed without creating an object. The static keyword allows data members to persist Values between different instances of a class.

            61. Debugging-dart programming

·         void main()

{

Int  x=10;

Int  y=20;

Y=90;

Print(x*y);

}

Output:

900

Process finished with exit code 0

Description:   This doc describes debugging features that you can enable in code. For a full list of debugging and profiling tools, see the Debugging page.

            62.  Runes – Dart Programming

·         void main()

{

String epicString=”Helo world”;

Print(epicString.codeUnits);

Print(epicString.codeUnitAt(1));

}

Output:

[72,101,108,111,32,87,11,114,108,100]

101

Description: rune is an integer representing a Unicode code point.

The String class in the dart:core library provides mechanisms to access runes. String code units / runes can be accessed in three ways

·         Using String.codeUnitAt() function

·         Using String.codeUnits property

·         Using String.runes property

 

            63.TypeDef operator  -Dart programming

·         typedef operator(int num1,int num2);

Addition(int num1,int num2)

{

Print(num1+num2);

}

Substraction(int num1,int num2)

{

Print(num1-num2);

}

Multiplication(int num1,int num2)

{

Print(num1*num2);

}

Division(int num1,int num2)

{

Print(num1/num2);

}

Calculation(int num1,int num2,Operator opAlias)

{

opAlias(num1,num20;

}

Void main()

{

Addition(10,5);

Substraction(10,5);

Multiplication(10,5);

Division(10,5);

}

Output:

15

5

50

2

·         typedef operator(int num1,int num2);

Addition(int num1,int num2)

{

Print(num1+num2);

}

Substraction(int num1,int num2)

{

Print(num1-num2);

}

Multiplication(int num1,int num2)

{

Print(num1*num2);

}

Division(int num1,int num2)

{

Print(num1/num2);

}

Calculation(int num1,int num2,Operator opAlias)

{

opAlias(num1,num20;

}

Void main()

{

Addition(10,5);

Substraction(10,5);

Multiplication(10,5);

Division(10,5);

Operator op=Addition;

Op(90,80);

Op=multiplication;

Op(10,8);

}

Output:

170

80

Description: Typedef in Dart is used to create a user-defined identity (alias) for a function, and we can use that identity in place of the function in the program code.

 

 

 

            64. Libraries – Dart programming

·         void main()

{

int  i=5;

print(i*i);

print(i^2)

}

Output:

25

7

·         library custom_lib;

import ‘dart:math’;

void main()

{

I=9;

Print(sqrt(i));

}

Output:

3

Description: Libraries contain ancillary code and data, which provides standalone program services, allowing for the modular sharing and modification of code and data 

            65.  Concurrency – Dart Programming

·         import  ‘dart:isolate’;

void Func(String  str)

{

Print(str);

}

Void main()

{

Isolate.spawn(Func,”1”);

Isolate.spawn(Func,”2”);

Isolate.spawn(Func,”3”);

Isolate.spawn(Func,”4”);

Isolate.spawn(Func,”5”);

Isolate.spawn(Func,”6”);

Print(“Normal 1”);

Print(“Normal 2”);

Print(“Normal 3”);

Print(“Normal 4”);

Print(“Normal 5”);

Print(“Normal 6”);

}

Output:

Normal  1

Normal 2

Normal 3

Normal 4

Normal 5

Normal 6

5

3

1

6

2

Process finished exit 0

            Description: Flutter/Dart is NOT single-threaded; Dart’s concurrency model is NOT Java’s thread; Future/Async/Await runs on the same thread and solves IO-bound problems, while Dart’s Isolate/Flutter’s compute runs on a different isolated (no-shared-memory) thread and solves CPU-bound ones.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

                                               

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

                                                

1.      Printing to the console in Dart programming

Void main()

{                                                                                                     

print(“Heloo world”);

print(“Batman”);

print(“Batman”);

print(“Batman”);

print(“Batman”);

print(“Batman”);

}

Output:

Heloo world

Batman

Batman

Batman

Batman

Batman

Description: when used in console based application it outputs in the terminal console.

2.       Comments -dart programming

//     Singleline comment

/* */   Multiline comment

Description: Just put two slash symbols at the beginning of the line you want to comment out. //This is a comment.(single line Comment), his method is usually used to comment out a block of code.(multiline comment).

3.       Print Variables Inside  to a String

·         Void main()

{

var  x=10;

var y=”Hello world”;

print(x);

print(y);

}

Output:

10

Hello world

·         Void Main()

{

Var  age=18;

Var  food=”pizza”;

Print(“Iam $age and I love eating $food”);

}

Output:

Iam 18 and I love eating pizza

·         Void main()

{

Var  age =90;

Var  food=”Pizza$age”;

Print(“Iam $age and I love eating $food”);

Print(food);

}

Output:

Iam 90 and I love eating pizza 90

Pizza 90

            Description: Variables used to print the value of the int along with the string.

4.      Console  Input – Dart programming

·         import  ‘dart:io’;

void main()

{

String str=stdin.readLineSync(); //Input should be given in console

Print(str);

Print(“End of  application”);

}

Output:

 Hello

Hello

End of application

                Description: The readLineSync() method of stdin allows to capture a String from the console

5.       Variables – Dart Programming

·         Void man()

{

Var epicName;

epicName=”Hello world”; or  var epicName=”Hello world”;

print(epicName);

}

Output:

HelloWorld

 

·         Void main()

{

String  epicName=”Hello world”;

epicName=89;

print(epicName);

}

Output:

Error compiling to javascript: Error: A value of type ‘dart.core::int’ can’t be assigned to a variable of type, ‘dart.core::string’.epicName=89;

·         Void main()

{

int epicName=90;

epicName=89;

print(epicName);

}

Output;

89

·         Void main()

{

Var epicName=”Hello world”;

epicName=”Batman”;

print(epicName);

}

Output:

Batmen

·         Void main()

{

Var epicName=90;

epicName=80;

print(epicName);

}

Output:

80

Description:  use the var keyword to define variables. once assigned a type is assigned you    can’t reassign a value with new type to the variable. Dart automatically infers the type of data from the right hand side.You can also define variables by explicitly providing type of data.

6.      Final and constant Variables – Dart programming

·         Void main()

{

Final var  v1=9;

Const var  v2=10;

V1=8;

V2=2;

Print(v1);

Print(v2);

}

Output:

Error:Setter not found:’v2’.

·         Voidmain(){

Const pi=3.1456;

final v1=9;const v2=10;

print(v1);print(v2);}

 output:Error

·         Int Epic()

{

Return 1;

}

Void main()

{

final v1=Epic();

const v2=89;

print (v1);

print(v2);

}}

Output:

1

                89

Description: const variables must have a value during compile time, for example  const PI = 3.14; , whereas variables that are final can only be assigned once, they need not be assigned during compile time and can be assigned during runtime.

7.       Static vs Dynamic Variables – Dart Programming

·         Class Epic

{

Var satus=0;

Static var statics=0;

epicFun()

{

Status++;

Statics++;

Print(‘status:$status & statics:$statics’);

}}

 

·         Void main()

{

Print(“E1”);

Epic e=new Epic();

e.epicFun();

e.epicFun();

e.EpicFun();

Print(“E2”);

Epic e2=new Epic();

e2.epicFun();

e2.epicFun();

e2.EpicFun();

}

Output:

E1

status:1 & statics:1

status:2 & statics:2

status:3 & statics:3

E2

status:1 & statics:4

status:2 & statics:5

status:3 & statics:6

Description: Dynamic you can access the methods and properties of it's type. But static doesn't allow to access it.

8.      DataTypes- Dart programming

·         Void main()

{

Int i=4;

Print(i);

Double d=9.5;

Print(d);

String s=”Hello world”;

Print(s);

bool  b =true;

print(b);

}

Output:

4

9.5

Hello world

True

Description:  basic data types that you can expect from a modern language.

  • Numbers
  • Strings
  • Booleans

9.      Boolean –Dart programming

·         Void main()

{

bool  var1;

Var2=67>89;

Print(var1);

}

Output:

False

·         Void main()

{

bool  var1;

Var2=67>89;

Print(var1);

}

                Output:

                True

Description: Boolean has trueb or false parameters,

10.  Numbers –Dart Programming

·         Void main()

{

String str =”5”;

int  i=num.parse(str);

print(i);

double d=9.5;

print(d);

}

Output:

5

9.5

·         Void main()

{

String str=”-5”;

int  i=num.parse(str);

print(i);

double d=num.parse(“6.78”);

print(d);

 print(d.round());

print(d.truncate());

print(i.isNegative);

} 

Output:

-5

6.78

7

6

True

Description: Number is one of datatype contains int ,double,negative,round and truncate.

11.  Arithmetic  Operators

·         Void main()

{

int num1=10;

int num2=5;

print(num1+num2);//addition

print(num1-num2);//substraction

print(num1*num2);//multiplication

print(num1/num2);// division

print(num~/num2);//integer division

print(num1%num2);//modulous 0

print(-num1); -10             //if num1 is -10 output is 10

//increment ++

Print(num1);//10

Num1++;

Print(num1);//11

                //decrement –

Print(num2);//5

Num2--;

Print(num2);//4

int numExtra=8;

print(numExtra++);//8

print(numExtra);//9

 

int numExtra=8 ;

print(++numExtra);//9

print(numExtra);//9

}

Output:

15

5

50

2

2

0

-10

 10

11

5

4

Description:Arithmetic operators included +,-,*,/,^,&. An expression is a special kind of statement that evaluates to a value. Every expression is composed of −

·        Operands − Represents the data

·        Operator − Defines how the operands will be processed to produce a value.

Consider the following expression – "2 + 3". In this expression, 2 and 3 are operands and the symbol "+" (plus) is the operator.

 

12.  Strings – Dart Programming

·         Void main()

{

String str=”Hello world”;

print(str);

String str2=’You\’re’;

print(str2);

String str2=”You’re”;

print(str2);

 

String str3=”””Hello world”””;

print(str3);

String str4=’’’Hello Hi world’’’;

print(str4 );

}

Output:

Hello world

You’re

Hello

      World

Hello

     Hi

     World

·         Void main()

{

String name=”Batman”;

String str1=”Hello ”;

String str2=”wo${name}rld”;

String result=str1+str2;

Print(result);

}

Output:

Hello WoBatmanrld

·         Void main()

{

String name=”Batman”;

String str1=”    Hello    ”;

String str2=”wo${6*6}rl$(name)d”;

String result=str1+str2;

Print(result);

Print(str1.length);

Print(str1.toLowerCase());

Print(str1.toUpperCase());

Print(str1.trim());

}

Output:

      Hello    Wo36Batmanrld

12

       hello

       HELLO

Hello

Description: A string can be either single or multiline. Single line strings are written using matching single or double quotes, and multiline strings are written using triple quotes.

13.  Relational Operators –Dart Programming

·         Void main()

{

Int num1=5;

Int num2=5;

Print(num1>num2);GT

Print(num1<num2);LT

Print(num1>=num2);GE

Print(num1<=num2);LE

Print(num==num2); EqualTo

Print(num!-num2);not equalto

} 

Output:

False

False

True

True

True

False

Description: Dart operators are as follows:

·         ==: For checking whether operands are equal

·         !=: For checking whether operands are different

For relational tests, the operators are as follows:

·         >: For checking whether the left operand is greater than the right one

·         <: For checking whether the left operand is less than the right one

·         >=: For checking whether the left operand is greater than or equal to the right one

·         <=: For checking whether the left operand is less than or equal to the right one.

14.  Type Test Operators

·         Void main()

{

int  i=10;

Print(i  is! String);//Is Type

Print(i  is! String);//is not type

}

Output:

False

True

Description: The Type test operators are used to check type of an object. These operators are handy for checking types at runtime.

15.  Logical Operators

·         Void main()

{

Int num1=10;

Int num2=5;

Print(num1>num2 && num1<20);// And operator

Print(num1>num2 || num1<20);//OR operator

Print(!(num1>num2));//NOT!

}

Output:

False

True      false

Description: Short-circuit Operators (&& and ||) The && and || operators are used to combine expressions. The && operator returns true only when both the conditions return true.

16.  Assignment operator

·         Void main()

{

int  i=20;

int  j=7;

j ??=10;

print(j);         //7

int num1=10;

print(num1);//10

num1 +=5;                //num1=num1+5;

print(num1);   //15

//substract

int num2=10;

print(num2);//10

num2 -=5;                //num2=num2-5;

print(num2);   //5

//multiply

int num3=10;

print(num3);//10

num3 *=5;                //num2=num3*5;

num3 *=5;               //250

print(num3);   //50

//Divide

double num4=10;

print(num4);

num4 /=5;                //num2=num2/5;

print(num4);   //2

}

Output:

7  

10

15

 10

 5

 10

 50

 10

 2

Description: Assignment operators are used in flutter to assign right side operand value to left side operand. The basic assignment operator in flutter is =(Equal). Equal is assign right side value to left side operand without any modification.

17.  Conditional Expressions

·         Void main()

{

Int num1=980;

Var result=num1<100? ”It is less than 100” : “It is more than 100”;

Print(result);

Int num2=null;

Var result2=num2??”It is null”;

int num3=7;

Var result2=num3??”It is null”;

Print(result2);

}

Output:

It is more than 100

It is null

7

Description: The ternary operator is technically that: an operator. But, it's also kind of an if/else substitute. It's also kind of a ?? alternative, depending on the situation. The ternary expression is used to conditionally assign a value. It's called ternary because it has three portions: the condition, the value if the condition is true, and the value if the condition is false.

18.  Bitwise Operators

·         Void main()

{

Int num1=55;

Int num2=78;

Print(num1&num2)//bitwise and&    6

Print(num1|num2)//bitwise Or|      127

Print(num1^num2)//bitwise Xor^     121

Print(~num2);      4294967217   

Print(num1<3);    false ;

}

Description: You can manipulate the individual bits of numbers in Dart. Usually, you'd use these bitwise and shift operators with integers.    

19.  Conditional IF statement

·         Void main()

{

int num1=100;

if(num1==0)

{

Print(“it is 0”);

}

else if(num1==10)

{

Print(“it is 10”);

}

 

else if(num1>=50)

{

Print(“Greater than 50”);//100 greater than 50

}

else

{

Print(“Default”); 45 lesser than 50 its default

}

}

Description: In normal If condition there are two parts If part and Else part. If the given condition is True then it will execute the If body part statements. If the given condition is False then it will automatically execute the Else part. 

20.  Switch statement – Dart programming

·         Void main()

{

  Int x=8;

Switch(x)

{

Case 0:print(“0”);

Break;

 

Case 1:print(“1”);

Break;

Case 2:print(“2”);

Break;

Case 3:print(“3”);

Break;

Default:print(“default”);

Break;

}}

Output:

8

Description: The switch statement evaluates an expression, matches the expression’s value to a  case clause and executes the statements associated with that case.

21.  For in loop

·         Void main()

{

Var i=[1,2,3,4,67,89,0];

for(  var val in i)

{

Print(val);

}}

Outpuyt:

1

2

3

4

67

89

0

Description: Dart for in loop is also a loop but a bit different than conventional for loop. It is mainly used to iterate over array’s or collection’s elements. The advantage for in loop has over the conventional for loop is clean code means fewer chances of error and more productivity. 

22.  For loop

·         Void main()

{

For(int i=0;i<=10;i++)

{

Print(i); 1 to 10

Print(i*i);   1 4 9 19 25 36 49………………………………..

}}

Output:

1 4 9 19 25 36 49……………………………….

Description:Use for loop directly inside a Column/ListView's children. . It is mainly used to iterate over array’s or collection’s elements.

23.  While loop

·         Void main()

{

Int i=0;

While(i<=100)

{

Print(i*i);

i++;

}}

Output:

1 4 9 25 36……………………100000

Description: while loop executes its code block as long as the condition is true. The functionality of while loop is very similar to for loop but in while loop first the condition is verified then while loop code block is executed and later on incremental/ decremental variable value is changed to control the flow of while loop.

24.  Do while

·         Void main()

{

Int i=0;

While(i<=100)

{

Print(i*i);

i++;

}

int x=10;

do

{

Print(x*x);

i++;

}

While(i<=5);

}

Output:

0

1

4

9

16

25

0

1

4

9

16

25

·         Void main()

{

int x=10;

do

{

Print(x*x);

i++;

}

While(x<=5);

}

Output:

100

Description: Do…while loop is similar to the while loop except that the do...while loop doesn’t evaluate the condition for the first time the loop executes. However, the condition is evaluated for the subsequent iterations. In other words, the code block will be executed at least once in a do…while loop.

25.  Break statement

·         Void main()

{

for(int i=0;i<=5;i++)

{

If(i==3)

{

Print(“Before break”);

Break;

Print(“after break”);

}

Print(i*i);

}

Print(“outside of loop”);}

Output:

0

1

4

Before break

outside loop

Description: The break statement is used to take the control out of a construct. Using break in a loop causes the program to exit the loop.

27.Continue statement

·         Void main()

{

for(int i=0;i<=5;i++)

{

If(i==3) //skip 3 and continue from 4

{

Print(“Before break”);

continue;

Print(“after break”);

}

Print(i*i);

}

Print(“outside of loop”);}

Output:

0

1

4

Before break

16

25

Outside of loop

Description: The continue statement skips the subsequent statements in the current iteration and takes the control back to the beginning of the loop. Unlike the break statement, the continue statement doesn’t exit the loop. It terminates the current iteration and starts the subsequent iteration.

   28. Basic Function:

·         void main()

{

Epic();

}

Void  Epic()

{Print(“Hello world”);}

Output:

Hello world

Description: Dart language is the base of Flutter. Hence creating functions in Flutter is the same as creating functions in Dart. In this blog post, let’s check how to create and use functions in Flutter. I hope it will be helpful for those who are new to Flutter.

29. Function Parameters

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99,0);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

}

Output:

12

-7

99

Description: Functions can have two types of parameters: required and optional. The required parameters are taking the front row, followed by any optional parameters.

        30.Functional optional named parameter

·         Void main()

{

Add(num2:5,  

num1:8,

num3:7);

}

Void Add(int num1,{int num2,int num3})

{

Print(num1);

print(num2);

print(num3);

}

Output:

8

5

Description:

31. Function Optional Positional parameters

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99,0);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

} 

Output:

12

-7

99

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

} 

Output:

12

-7

Uncaught exception:

Invalid argument:null

·         Void main()

{

Add(5,7);

Add(-9,2);

Add(99);

}

Void Add(int num1,[int num2])

{

Print(num1);

Print(num2);

}

Ouput:

5

7

-9

2

99

Null

32.Function Return values

·         Void main()

{

Add(10,9);

}

Void Add(int num1,int num2)

{

Print(num1+num2);

}

Output:

19

·         Void main()

{

int result=Add(10,9);

print(result);

print(result*result);

}

int Add(int num1,int num2)

{

return num1+num2;

}

Output:

19

361

Output: Functions in Dart are as simple as it can get, somewhat similar to javascript. All you need to do is provide a name, a return type and parameters.

33. Function Recursion

·         Void main()

{

Int res=calculateFactorial(6);

Print(res);

}

Int calculateFactorial(int n)

{

Print(“Hello”);

If(n<=0)

{

return 1;

}

else

{

Int result=(n*calculateFactorial(n-1));

return result;

}}

Output:

Hello

Hello

Hello

Hello

Hello

Hello

2

·         Void main()

{

Int res=calculateFactorial(15);

Print(res);

}

Int calculateFactorial(int n)

{

Print(“Hello”);

If(n<=0)

{

return 1;

}

else

{

Int result=(n*calculateFactorial(n-1));

return result;

}}

Output:

1307674368000

Description: Dart Recursion is the method where a function calls itself as its subroutine. It is used to solve the complex problem by dividing it into sub-part. A function which is called itself again and again or recursively, then this process is called recursion.

35. Lamda Function –Dart programming

·         Void main()

{

Epic();

}

Epic()=>print(“we are epic”);

String EpicReturn()=>”Hi”;

Output:

We are epic

Hi

Description: Lambda functions are also called Arrow functions. But here remember that by using Lambda function's syntax you can only return one expression. It must be only one line expression. Just like normal function lambda function cannot have a block of code to execute.

36. Try on block –Dart programming

·         Void main()

{

Int num1=10;

Int num2=6;

try{

print(num~/num2);

}

Catch(error)

{

Print(error);

}

 Print(“End of application”);

}

Output:

1

End of application

·         Void main()

{

Int num1=10;

Int num2=6;

try{

print(num~/num2);

}

On IntegerDivisionByZeroException

{

Print(“create divide by zero”);

}

 Print(“End of application”);

}

Description: The try block embeds code that might possibly result in an exception. The on block is used when the exception type needs to be specified. The catch block is used when the handler needs the exception object. The try block must be followed by either exactly one on / catch block or one finally block

37. Try catch block- Dart programming

·         void main()

{

Int num1=10;

Int num2=0;

Print(num1~/num2);

try

{

Print(num~/num2);

}

Catch(error)

{

Print(error);

}

Print(“End of application”);

}

Description: The try block embeds code that might possibly result in an exception. The on block is used when the exception type needs to be specified. The catch block is used when the handler needs the exception object. The try block must be followed by either exactly one on / catch block or one finally block.

38. Finally Block –Dart programming

·         void main()

{

Int num1=10;

Int num2=5;

Print(num1~/num2);

try

{

Print(num~/num2);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“Finally”);

}

Print(“End of application”);

}

·         void main()

{

Int num1=10;

Int num2=0;

Print(num1~/num2);

try

{

Print(num~/num2);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“Finally”);

}

Print(“End of application”);

}

Output:

Unsupported operation:Result of truncating

Division is infinity:10~/0

Finally

End of application

            Description: The finally block includes code that should be executed irrespective of an exception's occurrence. The optional finally block executes unconditionally after try/on/catch.

39. Try on catch block –Dart programming

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

print(num1~/num2);

double number=double.parse(pi);

print(number*number);

}

On IntegerDivisionByZeroException

{

Print(“cannot divide by zero”);

}

Catch(error)

{

Print(“catch block:$error”);

}

Print(“End of application”);

}

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

print(num1~/num2);

double number=double.parse(pi);

print($(number*number));

}

On FormatException

{

Print(“cannot divide by zero”);

}

Catch(error)

{

Print(“catch block:$error”);

}

Print(“End of application”);

}

Output:

2

Carch block:No such Method Error :No toplevel method’$’ declared.

Receiver :top-level

End of application

40. Manually Throw Exception:

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

print(num1~/num2);

double number=double.parse(pi);

print($(number*number));

}

On FormatException

{

Print(“cannot divide by zero”);

}

Catch(error)

{

Print(“catch block:$error”);

}

Print(“End of application”);

}

Output:

2

Catch block:No such Method Error :No toplevel method’$’ declared.

Receiver :top-level

End of application

·         void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

If(num1==100)

{

Throw new formatexception();

}

else

{

Print(num1~/num2);

On FormatException

{

Print(“Format cant be 100”);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“finally”);

}

Print(“End of application”);

}

Output:

FormatException

Finally

End of application

Description: Dart code can throw and catch exceptions. In contrast to Java, all of Dart’s exceptions are unchecked exceptions. Methods don’t declare which exceptions they might throw, and you aren’t required to catch any exceptions.

            41. CustomException- dart programming

Class EpicException implements Exception

{

Strng errMsg()=>”Epic Exception”;

}

void main()

{

Int num1=10;

Int num2=0;

String pi=”3.1459”;

try

{

If(num1==100)

{

Throw new formatexception();

}

else

{

Print(num1~/num2);

On FormatException

{

Print(“Format cant be 100”);

}

Catch(error)

{

Print(error);

}

finally

{

Print(“finally”);

}

Print(“End of application”);

}

Output:

Instance of ‘EpicException’

Finally

End of application

 

Description: If an unwanted condition occurs, you can throw an Exception that will be handled later. Dart already has the Exception class, but sometimes it's necessary to use custom exception class. With custom exception class, it makes us easier to use different handling for certain errors. In addition, by creating custom exceptions specific to business logic, it helps the users and the developers to understand the problem.In Dart, the custom exception class must implement Exception class. An exception usually has an error message and therefore the custom exception class should be able to return an error message.

42: Maps-Dart programming

·          void main()

{

Var epicmap={‘key1’:345,’key2:’sonu’};

Print(epicMap);

}

Output:

{‘key1’:345,’key2:’sonu’}

·         void main()

{

Var epicmap={‘key1’:345,’key2:’sonu’};

Vr epicMap = new Map();

epicMap[‘key3’]=67;

Print(epicMap);

Print(epicMap[‘key2’]);

epicMap.forEach(key,value)=>print(“$key and $value”));

}

Output:

{‘key1’:345,’key2:’sonu’}

EpicValue

Key1 and 345

Key2 and sonu                 

key3 and 67

·         void main()

{

Var epicMap = new Map();

epicMap[‘key3’]=67;

Print(epicMap);

Print(epicMap[‘key2’]);

epicMap.forEach(key,value)=>print(“$key and $value”));

}

Output:

{key3:67}

Null

Key3 and  67

Description: Defining maps is equally straight forward. Use the curly brackets { } to define a map.

                43. Lists -  dart programming

·         void main()

{

Var scores =new List(5);

scores[0] =10;

scores[1]=20;

scores[2]=30;

scores[3]=40;

scores[4]=50;

print(scores);

print(scores[1]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

}}

Output:

[10,20,30,40,50]

20

10

20

30

40

50

·         void main()

{

Var scores =new List(5);

scores[0] =10;

scores[1]=20;

scores[2]=30;

scores[3]=40;

scores[4]=50;

print(scores);

print(scores[1]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

}}

Output:

Uncaught exception:RangeError(index):Index out of range:no ndics are vakid

·         void main()

{

Var scores =new List(5);

Scores.add (10);

Scores.add(20);

Scores.add(30);

Scores.add(40);

Scores.add(50);

print(scores);

print(scores[1]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

for(int i=0;i<scores.length;i++)

{

Print(scores[i]);

}}

Output:

[10,20,30,40,50]

20

10

20

30

40

50

Description: Displaying lists of data is a fundamental pattern for mobile apps. Flutter includes the ListView widget to make working with lists a breeze.

          44. Enumeration –dart programming

·         Enum superheros

{

Yoda,

Batman,

Superman,

Lantern

}

Void main()

{

Print(SuperHeroes.yoda.index);

Print(SuperHeroes.Batman.index);

Print(SuperHeroes.Superman.index);

Print(SuperHeroes.Lantern.index);

}

Output:

1

2

3

4

Description: Enums are an essential part of programming languages. They help developers define a small set of predefined set of values that will be used across the logics they develop. In Dart language, which is used for developing for FlutterEnums have limited functionality.

                45.  SET –Dart programming

·         Void main()

{

Set epicset=new Set();

epicset.add(10);

epicset.add(20);

epicset.add(30);

epicset.add(40);

epicset.add(50);

print(epicset);

  print(epicset[0]);

}

Output:

{10,20,30,40,50}

Error :[] not defined

·         Void main()

{

Set epicset=new Set();

epicset.add(10);

epicset.add(20);

epicset.add(30);

epicset.add(40);

epicset.add(50);

print(epicset);

for(var value in epicset)

{

Print(value);

}

Set epicset2=new set.from([1,2,3,4,]);

Print(epicset);

}

Output:

{10,20,30,40,50}

10

20

30

40

50

{1,2,3,4}

Description:  Dart is a special case in List where all the inputs are unique i.e it doesn’t contain any repeated input. It can also be interpreted as an unordered array with unique inputs. The set comes in play when we want to store unique values in a single variable without considering the order of the inputs. The sets are declared by the use of a set keyword.

            46. HashMap –dart programming

·         Void main()

{

Var hash=new HashMap();

hash[‘key1’]=10;

hash[‘key2’]=”Hello world”;

print(hash);

print(hash[‘key2’]);

}

Output:

{key1:10,key2:Hello world}

Hello world

Description:  

The keys of a HashMap must have consistent Object.== and Object.hashCode implementations. This means that the == operator must define a stable equivalence relation on the keys (reflexive, symmetric, transitive, and consistent over time), and that hashCode must be the same for objects that are considered equal by ==.

                47.Generics –dart programming

·         Void main()

{

List <int> epicList=new List<int>();

epicList.add(1);

epicList.add(2);

epicList.add(3);

epicList.add(4);

epicList.add(5);

print(epiclist);

}

Output:

[1,2,3,4,5]

Description: Collection generics can help you be certain every element within a collection is of the expected type. It's also important to be able to trust that data that coming out of futures or streams has the right structure, and Dart's generics feature allows you to specify what that structure should be.

            48.Queue –dart programming

·         Import ‘dart:collection’;

Void main()

{

//FIFO

Queue 1 =new Queue();

q.add(10);

q.add(20);

q.add(30);

q.add(40);

q.add(50);

print(q);

q.addFirst(23);

q.addLast(90);

print(q);

}

Output:

{1,2,3,4,5}

{23,1,2,3,4,5,90}

Description: Queue is a collection that can be manipulated at both ends. One can iterate over the elements of a queue through forEach or with an Iterator. It is generally not allowed to modify the queue (add or remove entries) while an operation on the queue is being performed.

            49.Basic Class Example-Dart

·         Class vehicle

{

Int speed=60;

Void drive()

{

Print(‘drive drive “);

}}

Void main()

{

Vehicle v1=new vehicle();

Vehicle v2=new vehicle();

v1.Drive();

Print(v1.maxspeed);

v1.maxspeed=100;

Print(v1.maxspeed);

Print(v2.maxspeed);

}

Output:

Drive drive drive

60

100

60

Description: Dart has some conventions and special syntax to be aware of when designing classes and instantiating objects of those classes. There is more than one way to do almost anything, but what are the best practices in Dart? Here, we'll explore a few for class design and object instantiation.

50.Iterating over collections:

·         Void main()

{

List<int> epicList =new List<int>();

epiclist.add(1);

epiclist.add(2);

epiclist.add(3);

epiclist.add(4);

epiclist.add(5);

print(epiclist);

 

Iterator itr = epicList.iterator;

While(itr.moveNext())

{

Print(itr.current^2);

}

Output:

[1,2,3,4,5]

·         Void main()

{

List<int> epicList =new List<int>();

epiclist.add(1);

epiclist.add(2);

epiclist.add(3);

epiclist.add(4);

epiclist.add(5);

print(epiclist);

 

Iterator itr = epicList.iterator;

While(itr.moveNext())

{

Int result=itr.current;

 

Print(result*result);

}

}

Output:

[1,2,3,4,5]

1

4

9

16

25

Description: Iterate over the elements of an Iterable using the for-in loop construct, which uses the iterator getter behind the scenes. For example, you can iterate over all of the keys of a Map, because Map keys are iterable.

            51. Class Named Constructors-Dart Programming

·         Class vehicle

{

Vehicle(int speed)

{

Print(“hi”);

Maxspeed=speed;

}

Vehicle.empty

{

Print(“Named constructors”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void main()

{

Vehicle v1=new vehicle(100);

Vehicle v2=new vehicle(90);

V1.Drive();

Print(v1.maxspeed);

V1.maxspeed=89;

Print(v1.maxSpeed);

Print(v2.maxSpeed);

}

Output:

Hi

Hi

Hi

Drive drive drive

100

89

90

·         Class vehicle

{

Vehicle(int speed)

{

Print(“hi”);

Maxspeed=speed;

}

Vehicle.empty

{

Print(“Named constructors”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void main()

{

Vehicle v1=new vehicle(100);

Vehicle v2=new vehicle.empty();

V1.Drive();

Print(v1.maxspeed);

V1.maxspeed=89;

Print(v1.maxSpeed);

Print(v2.maxSpeed);

}

 

Output:

Hi

Hi

Hi

Drive drive drive

100

89

60

Description: Constructor is a special method of Dart class which is automatically called when the object is created. The constructor is like a function with/without parameter but it doesn't have a return type. Now you can create new object using a constructor.

                52. Class Constructors – Dart Programming

·         Class vehicle()

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void main()

{

Vehicle v1=new vehicle(100);

Vehicle v2=new vehicle(90);

V1.Drive();

Print(v1.maxspeed);

V1.maxspeed=89;

Print(v1.maxSpeed);

Print(v2.maxSpeed);

}

Output:

Hi

Hi

Drive drive drive

100

89

90

Description: constructor is like a function with/without parameter but it doesn't have a return type. Now you can create new object using a constructor.

53. Class Inheritance

·         Class vehicle

{

Vehicle(int speed)

{

Print(“Hi”);

_maxspeed=speed;

}

Vehicle.empty

{

Print(“Named constructors”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

Void set maxSped=60;

Void set maxSpeed(int speed)

{

_maxSpeed=speed*2;

}

Void get maxSpeed

{

Return _maxSpeed;

}}

Class car extends vehicle

{

Car()

{

 

Void Hello()

{

Print(“Hello,Iam a car”);

}}

Void main()

{

Car c1=new Car();

c1.Drive();

c1.maxSpeed=10;

print(c1.maxSpeed);

c1.Hello();

}

Description: This is the simplest example of a custom widget in Flutter. Note that it uses the extends keyword to indicate that the class should inherit properties and methods from StatelessWidget, which itself inherits from the Widget class.

                54.  Class custom getters and setters

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car extends vehicle

{

Car()

{

Print(“custom constructor”);

}

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Output:

Hi

Custom constructor

Drive drive drive

60

20

Hello , I’m a car

Description: Getters and setters are special methods that provide read and write access to an object’s properties. Each instance variable of your class has an implicit getter, and a setter if needed. In dart, you can take this even further by implementing your own getters and setters.

            55.Method –overriding  Dart Programs

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car extends vehicle

{

Car()

{

Print(“custom constructor”);

}

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Output:

Hi

Custom constructor

Drive drive drive

60

20

Hello , I’m a car

Description: The annotation @override marks an instance member as overriding a superclass member with the same name. The annotation applies to instance methods, getters and setters, and to instance fields, where it means that the implicit getter and setter of the field is marked as overriding, but the field itself is not.

                56.  Abstract class: -Dart programming

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Output:

Hi

Custom constructor

Drive drive drive

60

20

Hello , I’m a car

Error compiling to javascript:The non –abstract class

 ‘car’ is  missing implementation for these members:

 ‘maxSpeed’,’_maxspeed’,’maxspeed=’, ’_maxspeed=’,

Description: An Abstract class in Dart is defined for those classes which contain one or more than one abstract method (methods without implementation) in them. Whereas, to declare abstract class we make use of the abstract keyword. So, it must be noted that a class declared abstract may or may not include abstract methods but if it includes an abstract method then it must be an abstract class.

                57. This Keyword – Dart Programming

·          Void main()

{

 Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

this._maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Void main()

{

Car c1=new car();

C1.Drive();

Print(c1.maxspeed);

C1.maxspeed=10;

Print(c1.maxspeed);

C1.Hello();

}

Output:

Hi

Custom constructor

New drive

60

20

Hello, Iam a car

            Description: this keyword represents an implicit object pointing to the current class object. It refers to the current instance of the class in a method or constructor. The this keyword is mainly used to eliminate the ambiguity between class attributes and parameters with the same name. When the class attributes and the parameter names are the same this keyword is used to avoid ambiguity by prefixing class attributes with this keyword.

            58. Multiple class Inheritance

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Class bmw extends car

{

Void hey()

{

Print(“Grandchild class”);

}}

Void main()

{

BMW b1=new BMW();

b1.Hey();

b1.Drive();

}

Output:

Hi

 Custom constructor

Grandchild class

New Drive

Description: Multiple Inheritance: When a class inherits more than one parent class than this inheritance occurs. Dart doesn't support this. 

            59. Super keyword –dart programming

·         Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

@override

Void Drive()

{

super.Drive();

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Void main()

{

BMW b1=new BMW();

b1.Hey();

b1.Drive();

}

 

Output:

Hi

Custom constructor

Drive drive drive

New Drive

60

10

Hello, Iam a car

Description: super is used to call the constructor of the base class. So in your example, the constructor of CardTitle is calling the constructor of StatelessWidget .

            60.  Static Keyword –dart programming

Abstract Class vehicle

{

Vehicle()

{

Print(“Hi”);

}

Void drive()

{

Print(“Drive drive drive”);

}

Int maxSpeed=60;

}

static int _maxspeed=60;

void set maxspeed(int speed)

{

_maxSpeed =speed*2;

}

int get maxspeed

{

return _maxspeed;

}

Class car implements vehicle

{

Car()

{

Print(“custom constructor”);

}

 

@override

Void Drive()

{

Print(“New Drive”);

}

Void Hello()

{

Print(“Heloo , I’m a car”);

} }

Void main()

{

Car c1=new car();

Ca1.Drive();

Print(Car.maxspeed);

Car.maxspeed=10;

Print(Car.maxspeed);

C1.Hello();

 

Car c2= new Car();

Print(car.maxSpeed);

}

Output:

Hi

Custom constructor

New drive

60

10

Hello, Iam a car

Hi

Custom constructor

10

                Description: The static keyword is used for a class-level variable and method that is the same for every instance of a class, this means if a data member is static, it can be accessed without creating an object. The static keyword allows data members to persist Values between different instances of a class.

            61. Debugging-dart programming

·         void main()

{

Int  x=10;

Int  y=20;

Y=90;

Print(x*y);

}

Output:

900

Process finished with exit code 0

Description:   This doc describes debugging features that you can enable in code. For a full list of debugging and profiling tools, see the Debugging page.

            62.  Runes – Dart Programming

·         void main()

{

String epicString=”Helo world”;

Print(epicString.codeUnits);

Print(epicString.codeUnitAt(1));

}

Output:

[72,101,108,111,32,87,11,114,108,100]

101

Description: rune is an integer representing a Unicode code point.

The String class in the dart:core library provides mechanisms to access runes. String code units / runes can be accessed in three ways

·         Using String.codeUnitAt() function

·         Using String.codeUnits property

·         Using String.runes property

 

            63.TypeDef operator  -Dart programming

·         typedef operator(int num1,int num2);

Addition(int num1,int num2)

{

Print(num1+num2);

}

Substraction(int num1,int num2)

{

Print(num1-num2);

}

Multiplication(int num1,int num2)

{

Print(num1*num2);

}

Division(int num1,int num2)

{

Print(num1/num2);

}

Calculation(int num1,int num2,Operator opAlias)

{

opAlias(num1,num20;

}

Void main()

{

Addition(10,5);

Substraction(10,5);

Multiplication(10,5);

Division(10,5);

}

Output:

15

5

50

2

·         typedef operator(int num1,int num2);

Addition(int num1,int num2)

{

Print(num1+num2);

}

Substraction(int num1,int num2)

{

Print(num1-num2);

}

Multiplication(int num1,int num2)

{

Print(num1*num2);

}

Division(int num1,int num2)

{

Print(num1/num2);

}

Calculation(int num1,int num2,Operator opAlias)

{

opAlias(num1,num20;

}

Void main()

{

Addition(10,5);

Substraction(10,5);

Multiplication(10,5);

Division(10,5);

Operator op=Addition;

Op(90,80);

Op=multiplication;

Op(10,8);

}

Output:

170

80

Description: Typedef in Dart is used to create a user-defined identity (alias) for a function, and we can use that identity in place of the function in the program code.

 

 

 

            64. Libraries – Dart programming

·         void main()

{

int  i=5;

print(i*i);

print(i^2)

}

Output:

25

7

·         library custom_lib;

import ‘dart:math’;

void main()

{

I=9;

Print(sqrt(i));

}

Output:

3

Description: Libraries contain ancillary code and data, which provides standalone program services, allowing for the modular sharing and modification of code and data 

            65.  Concurrency – Dart Programming

·         import  ‘dart:isolate’;

void Func(String  str)

{

Print(str);

}

Void main()

{

Isolate.spawn(Func,”1”);

Isolate.spawn(Func,”2”);

Isolate.spawn(Func,”3”);

Isolate.spawn(Func,”4”);

Isolate.spawn(Func,”5”);

Isolate.spawn(Func,”6”);

Print(“Normal 1”);

Print(“Normal 2”);

Print(“Normal 3”);

Print(“Normal 4”);

Print(“Normal 5”);

Print(“Normal 6”);

}

Output:

Normal  1

Normal 2

Normal 3

Normal 4

Normal 5

Normal 6

5

3

1

6

2

Process finished exit 0

            Description: Flutter/Dart is NOT single-threaded; Dart’s concurrency model is NOT Java’s thread; Future/Async/Await runs on the same thread and solves IO-bound problems, while Dart’s Isolate/Flutter’s compute runs on a different isolated (no-shared-memory) thread and solves CPU-bound ones.