0% found this document useful (0 votes)
5 views

Lesson1 - Dart Basic Programming.pptx

Dart is an open-source programming language developed by Google, primarily used for mobile and web app development with Flutter. The document covers Dart's syntax, comments, variable types, data types, control flow structures, loops, and functions, providing essential guidelines and examples. Key features include static and dynamic variables, null safety, and various control flow mechanisms like if statements and loops.

Uploaded by

Loki Legends
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lesson1 - Dart Basic Programming.pptx

Dart is an open-source programming language developed by Google, primarily used for mobile and web app development with Flutter. The document covers Dart's syntax, comments, variable types, data types, control flow structures, loops, and functions, providing essential guidelines and examples. Key features include static and dynamic variables, null safety, and various control flow mechanisms like if statements and loops.

Uploaded by

Loki Legends
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

BASIC DART

PROGRAMMING

FLUTTER
DART
• Dart is an open-source general-purpose programming language developed by Google. It supports application development on
both the client and server side. However, it is widely used for the development of Android apps, iOS apps, IoT(Internet of Things),
and web applications using the Flutter Framework.
• . Syntactically, Dart bears a strong resemblance to Java, C, and JavaScript. It is a dynamic object-oriented language with closure
and lexical scope. The Dart language was released in 2011 but came into popularity after 2015 with Dart 2.0.
DART COMMENTS
• In every programming language comments play an important role for a better understanding of the code in the future or by any
other programmer. Comments are a set of statements that are not meant to be executed by the compiler. They provide proper
documentation of the code.
Types of Dart Comments:
• Dart single line comment is used to comment a line until line break occurs. It is done using a double forward-slash (//).
• Dart Multiline comment is used to comment out a whole section of code. It uses ‘/*’ and ‘*/’ to start and end a multi-line
comment respectively.
• Dart Documentation Comments are a special type of comment used to provide references to packages, software, or
projects.Dart supports two types of documentation comments “///”(C# Style) and “/**…..*/”(JavaDoc Style). It is preferred to
use “///” for doc comments as many times * is used to mark list items in a bulleted list which makes it difficult to read the
comments. Doc comments are recommended for writing public APIs.
DART VARIABLES
• A variable name is the name assigned to the memory location where the user stores the datas and that data can be fetched when required with
the help of the variable by calling its variable name. There are various types of variable that are used to store the data. The type which will be
used to store data depends upon the type of data to be stored.
Conditions to Write Variable Name
Conditions to write variable names or identifiers are as follows:
• Variable names or identifiers can’t be the keyword.
• Variable names or identifiers can contain alphabets and numbers.
• Variable names or identifiers can’t contain spaces and special characters, except the underscore(_) and the dollar($) sign.
• Variable names or identifiers can’t begin with a number.
TYPES OF VARIABLES
1. Static Variable
2. Dynamic Variable
3. Final or const
STATIC VARIABLES

• static variable is shared among all instances of a


class.
• It is associated with the class rather than any
specific object.
• The value of the static variable is stored in a
fixed memory location and is retained across
different method calls or instances.

OUTPUT: 2
DYNAMIC VARIABLES
• A dynamic variable can hold values of any type and allows its type to change at runtime.
• It is defined using the dynamic keyword.
• Be cautious when using dynamic as it bypasses compile-time type checking.

OUTPUT: 3.14157
FINAL OR CONST VARIABLES
• A final variable can be assigned only once, and its value cannot be modified after being initialized.
• It is initialized at runtime when accessed.
• A const variable is a compile-time constant, meaning its value is determined during compilation.
• It cannot be changed and must be initialized with a constant value.

OUTPUT:
Pasado
Pasado Again!!
NULL SAFETY IN DART

• In Dart, by default a variable can’t be assigned


Null value till it is defined that the variable can
store Null value in it. This to avoid cases where
user assign null value in Dart.
DART DATA TYPES
• Like other languages (C, C++, Java), whenever a variable is created, each variable has an associated data type. In Dart
language, there are the types of values that can be represented and manipulated in a programming language.
NUMBERS
• Like other languages (C, C++, Java), whenever a variable is created, each variable has an associated data type. In Dart
language, there are the types of values that can be represented and manipulated in a programming language.
• The number in Dart Programming is the data type that is used to hold the numeric value.
Dart numbers can be classified as:
1. int: data type is used to represent whole numbers (64-bit Max).
2. double: data type is used to represent 64-bit precise floating-point numbers.
3. num: type is an inherited data type of the int and double types.
STRING
• It used to represent a sequence of characters. It is a sequence of UTF-16 code units. The keyword string is used to represent
string literals. String values are embedded in either single or double-quotes.
BOOLEANS
• It represents Boolean values true and false. The keyword bool is used to represent a Boolean literal in DART.
LIST
• List data type is similar to arrays in other programming languages. A list is used to represent a collection of objects. It is an
ordered group of objects.
Declaration of List
MAPS
• The Map object is a key and value pair. Keys and values on a map may be of any type. It is a dynamic collection.
RESULT
• Control flow in Dart determines the order in which
the statements in a program are executed. Dart
provides several control flow structures, including CONTROL FLOW
conditional statements, loops, and exception
handling.
SWITCH CASE STATEMENT
• In Dart, switch-case statements are a simplified version of the nested if-else statements. Its approach is the same as that in
Java.

The default case is the case whose body is executed if none of the above
cases matches the condition.

Rules to follow in switch case:

1. There can be any number of cases. But values should not be repeated.
2. The case statements can include only constants. It should not be a
variable or an expression.
3. There should be a flow control i.e break within cases. If it is omitted
than it will show error.
4. The default case is optional.
5. Nested switch is also there thus you can have switch inside switch.
IF STATEMENT
• The if statement allows you to execute a block of code only if a condition is true.

Output:
The number is positive.
IF-ELSE STATEMENT
• The if-else statement lets you handle two possible outcomes. If the condition is true, it executes the if block; otherwise,
it executes the else block.

Output:
The number is not positive.
NESTED IF-ELSE STATEMENT
• A nested if-else allows you to check multiple conditions by placing an if-else statement inside another if or else block.

Output:
The number is positive and odd.
NESTED IF-ELSE IF-ELSE STATEMENT
• You can also combine else if with nested conditions for more complex logic.

Output:
The number is negative.
DART – LOOPS
• A looping statement in Dart or any other programming language is used to repeat a particular set of commands until
certain conditions are not completed. There are different ways to do so. They are:
1. for loop
2. for… in loop
3. for each loop
4. while loop
5. do-while loop
FOR LOOP
• For loop in Dart is similar to that in Java and also the flow of execution is the same as that in Java.
FOR IN LOOP
• For…in loop in Dart takes an expression or object as an iterator. It is similar to that in Java and its execution flow is also
the same as that in Java.
FOR EACH LOOP
• The for-each loop iterates over all elements in some container/collectible and passes the elements to some specific
function.

Parameters:
• f( value): It is used to make a call to the f function for each element in the collection.
WHILE LOOP
• The body of the loop will run until and unless the condition is true.
DO WHILE LOOP
• The body of the loop will be executed first and then the condition is tested.
DART – LOOP CONTROL STATEMENTS (BREAK AND CONTINUE)
Break Statement:
• This statement is used to break the flow of control of the loop i.e if it is used within a loop then it will terminate the loop
whenever encountered. It will bring the flow of control out of the nearest loop.
Continue Statement:
• While the break is used to end the flow of control, continue on the other hand is used to continue the flow of control. When a
continue statement is encountered in a loop it doesn’t terminate the loop but rather jump the flow to next iteration.
WITH BREAK STATEMENT
WITH CONTINUE STATEMENT
• In Dart, functions are blocks of reusable code that
perform a specific task. Functions can be defined
with or without parameters and can return values or
FUNCTIONS
be void (i.e., not return anything).
BASIC FUNCTION
• A simple function that doesn't take parameters and returns nothing (i.e., void):
FUNCTION WITH PARAMETERS
• You can define functions that take parameters (inputs).
FUNCTION WITH RETURN VALUE
• Functions can also return values. The return type is specified before the function name.
ARROW FUNCTIONS (FAT ARROW FUNCTIONS)
• Dart also supports a shorthand syntax for functions that consist of a single expression. This is called the "fat arrow" (=>)
syntax.
OPTIONAL PARAMETERS
• Dart functions can accept optional parameters, which can be either positional or named.
• These parameters are placed inside square brackets [].
NAMED OPTIONAL PARAMETERS
• Named parameters are placed inside curly braces {}. These parameters are optional and can be called in any order
DEFAULT VALUES FOR PARAMETERS
• You can provide default values for optional parameters.
FUNCTION TYPES (TYPE ALIASES)
• You can define a function type using typedef.
RECURSIVE FUNCTIONS
• A function can call itself. This is called recursion.
HIGHER-ORDER FUNCTIONS:
• A higher-order function is one that takes another function as an argument or returns a function.
THANK YOU ☺

RYAN FERMO

You might also like