4. Dart Programming Language
● Open-Source General-Purpose programming language.
● Developed by Google.
● This meant for the server as well as the browser.
● an object-oriented language.
● C-style syntax.
8. Where Dart Using?
● Flutter Created on top of Dart.
● Flutter has an Power Full Engine to
perform smooth and lag less
performance.
● Flutter used for:
10. First Dart Program
// Entry point to Dart program
main() {
print('Hello from Dart');
}
• main() - The special, required, top-level function where app execution starts.
• Every app must have a top-level main() function, which serves as the entry
point to the app.
11. Comments In Dart
• Dart supports both single line and multi line comments
// Single line comment
/* This is
an example
of multi line
comment */
12. Built in Types
• number
• int - Integer (range -253 to 253)
• double - 64-bit (double-precision)
• string
• boolean – true and false
• symbol
• Collections
• list (arrays)
• map
• set
• runes (for expressing Unicode characters in a string)
13. Variable Initializing
● var name=”technoship”;
● var reg=123;
var keyword used to create static variables.
● dynamic name=”technoship”;
● dynamic reg=123;
dynamic keyword used to create dynamic variables.
● String name=”technoship”;
● int reg=123;
Variables can initialize using its data type.
14. List and Map
● List
List names=<String>[“Arun”,”Alen”];
List is used to store same data type items
● Map
Map rollno_name=<int,String>{1:”Arun”,2:”Alen”};
Map is an object that associates keys and values
15. String Interpolation
● Identifiers could be added within a string literal using $identifier or
$varaiable_name syntax.
var user = 'Bill';
var city = 'Bangalore';
print("Hello $user. Are you from $city?");
// prints Hello Bill. Are you from Bangalore?
● You can put the value of an expression inside a string by using ${expression}
print('3 + 5 = ${3 + 5}'); // prints 3 + 5 = 8
17. Operands and operator
● 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.
18. operators that are available in Dart.
● Arithmetic Operators
● Equality and Relational Operators
● Type test Operators
● Bitwise Operators
● Assignment Operators
● Logical Operators
27. Control flow statements
● if and else
● for loops (for and for in)
● while and do while loops
● break and continue
● switch and case
28. if and else
● if and else
var age = 17;
if(age >= 18){
print('you can vote');
}
else{
print('you can not vote');
}
● curly braces { } could be omitted when the blocks have a single line of code
29. Conditional Expressions
● Dart has two operators that let you evaluate expressions that might otherwise
require ifelse statements −
○ condition ? expr1 : expr2
● If condition is true, then the expression evaluates expr1 (and returns its value);
otherwise, it evaluates and returns the value of expr2.
● Eg:
○ var res = 10 > 12 ? "greater than 10":"lesser than or equal to 10";
● expr1 ?? expr2
● If expr1 is non-null, returns its value; otherwise, evaluates and returns the
value of expr2
30. else if
● Supports else if as expected
var income = 75;
if (income <= 50){
print('tax rate is 10%');
}
else if(income >50 && income <80){
print('tax rate is 20%');
}
else{
print('tax rate is 30%');
}
31. While & do..while
● While in dart
var num=0;
while(num<5){
print(num);
i=i+1;
}
● do..while in dart
var num=0;
do{
print(num);
i=i+1;
}while(num<5);
32. for loops
● Supports standard for loop (as
supported by other languages
that follow C like syntax)
for(int ctr=0; ctr<5; ctr++){
print(ctr);
}
● Iterable classes such as List and
Set also support the for-in form of
iteration
var cities=['Kolkata','Bangalore'];
for(var city in cities){
print(city);
}
33. switch case
● Switch statements compare integer, string, or compile-time constants
● Enumerated types work well in switch statements
● Supports empty case clauses, allowing a form of fall-through
var window_state = 'Closing';
switch(window_state){
case 'Opening' : print('Window is opening');
Break;
case 'Closing' : print('Window is Closing');
break;
default:print(“Non of the options”);
38. Named Parameters
● eg:
Function definition :
void enableFlags({bool bold, bool hidden}) {...}
Function call:
enableFlags(bold: true, hidden: false);
39. Optional Parameters
● Wrapping a set of function parameters in [ ] marks them as optional positional
parameters:
● Eg:
Function definition :
void enableFlags(bool bold, [bool hidden]) {...}
40. Default Parameters
● Your function can use = to define default values for both named and
positional parameters.
● The default values must be compile-time constants.
● default value is provided, the default value is null.
● Eg:
void enableFlags({bool bold = false, bool hidden = false}) {...}
42. Exception
● Exceptions are errors indicating that something unexpected happened.
● When an Exception occurs the normal flow of the program is disrupted and
the program/Application terminates abnormally.
● Eg
var n=10~/0;
Output:
Error occured ZeroDivision.
43. The try / on / catch Blocks
● syntax
try {
// code that might throw an exception
}
on Exception1 {
// code for handling exception
}
catch Exception2 {
// code for handling exception
}finally {
// code that should always execute; irrespective of the exception
}
44. Example try / on / catch
● try {
res = 10 ~/ 0;
}
on IntegerDivisionByZeroException
{
print('Cannot divide by zero');
}
● try {
res = 10 ~/ 0;
}
catch(e) {
print(e);
}
46. Throw
● The throw keyword is used to explicitly raise an exception.
● A raised exception should be handled to prevent the program from exiting
abruptly.
● The syntax for raising an exception explicitly is −
throw new Exception_name();
47. Eg : of Throws
main() {
try {
test_age(-2);
}
catch(e) {
print('Age cannot be negative');
}
}
void test_age(int age) {
if(age<0) {
throw new FormatException();
}
}
49. OOPs (Object-Oriented Programming System)
● Object means a real-world entity such as a pen, chair, table, computer, watch,
etc.
● Object-Oriented Programming is a methodology or paradigm to design a
program using classes and objects.
● It simplifies software development and maintenance by providing some
concepts:-
○ Object
○ Class
○ Inheritance
○ Polymorphism
○ Abstraction
○ Encapsulation
50.
51. Object
● Any entity that has state and behavior is known as an object. For example, a
chair, pen, table, keyboard, bike, etc. It can be physical or logical.
● An Object can be defined as an instance of a class.
● An object contains an address and takes up some space in memory.
● Objects can communicate without knowing the details of each other's data or
code.
● Example: A dog is an object because it has states like color, name, breed, etc.
as well as behaviors like wagging the tail, barking, eating, etc.
52. Class
● Collection of objects is called class. It is a logical entity.
● A class can also be defined as a blueprint from which you can create an
individual object. Class doesn't consume any space.
53. Inheritance
● When one object acquires all the properties and behaviors of a parent object,
it is known as inheritance.
● It provides code reusability.
● It is used to achieve runtime polymorphism.
● Types of inheritance:-
○ Single Inheritance
○ Multiple Inheritance
○ Hierarchical Inheritance
○ Multilevel Inheritance
○ Hybrid Inheritance (also known as Virtual Inheritance)
54.
55. Polymorphism
● If one task is performed in different ways, it is known as polymorphism.
● For example: to convince the customer differently, to draw something, for
example, shape, triangle, rectangle, etc.
● Another example can be to speak something; for example, a cat speaks
meow, dog barks woof, etc.
56. Abstraction
● Hiding internal details and showing functionality is known as abstraction.
● For example phone call, we don't know the internal processing.
57. Encapsulation
● Binding (or wrapping) code and data together into a single unit are known as
encapsulation.
● For example, a capsule, it is wrapped with different medicines.
59. Declaring a Class in dart
● Use the class keyword to declare a class in Dart.
● A class definition starts with the keyword class followed by the class name;
● The class body enclosed by a pair of curly braces.
● Syntax
class class_name {
<fields>
<getters/setters>
<constructors>
<functions>
}
60. A class definition can include the following −
● Fields − A field is any variable declared in a class. Fields represent data
pertaining to objects.
● Setters and Getters − Allows the program to initialize and retrieve the values
of the fields of a class. A default getter/ setter is associated with every class.
However, the default ones can be overridden by explicitly defining a setter/
getter.
●