Dart
Dart
App Development
DART PROGRAMMING
Contents
• Setup
• Fundamentals
• Data Types
• String
• Type Conversion
• Constant
• Null
• Operators
• Loops
• Collection [List, Set, Map]
• Function
• Class
• Exception Handling
Setup Dart SDK
• To install Dart SDK first you visit- https://dart.dev
Install Dart SDK
Install Visual Studio Code
• https://code.visualstudio.com/
Open Dartpad
• https://dartpad.dev
Fundamentals
• What is Dart Programming
• Dart is a main programming language to develop cross platform
mobile application using flutter framework.
• Why Dart Programming
• Dart has a declarative and programmable layout that is easy to read
and visualize. Hence, Flutter doesn't require a separate declarative
layout language like XML. It is easy for Flutter to provide advanced
tooling since all the layout in one language and in a central place.
Why is Dart better than Java?
• Dart is a programming language used by flutter, flutter is used to
create cross-platform apps (for android & ios). If your plan is to only
create apps for android only you should definitely go with java, it will
run and look better in almost every way.
What is the advantage of Dart?
• Dart is an interesting programming language with features to facilitate
Web, mobile and command line apps. Its major advantages are
its stability and ease of learning. In the case of Web applications, the
combination with AngularDart makes it a very powerful tool.
• Four Reasons
• Dart enforces object-oriented programming
• Dart compilers are quick and reliable
• Dart has a clean and type-safe syntax
• Dart has a strong developer community
Dart Programming Features
Open Source
• Dart provides the flexibility to compile the code and fast as well. It
supports two types of compilation processes, AOT (Ahead of Time)
and JIT (Just-in-Time). The Dart code is transmitted in the other
language that can run in the modern web-brewers.
Objects
• The Dart treats everything as an object. The value which assigns to the
variable is an object. The functions, numbers, and strings are also an
object in Dart. All objects inherit from Object class.
Browser Support
• The Dart supports all modern web-browser. It comes with the dart2js
compiler that converts the Dart code into optimized JavaScript code
that is suitable for all type of web-browser.
Community
• Dart has a large community across the world. So if you face problem
while coding then it is easy to find help. The dedicated developers'
team is working towards enhancing its functionality.
Flutter Download
Get Started
Install
Key Points to Remember
• Everything in Dart is treated as an object including, numbers, Boolean,
function, etc. like Python. All objects inherit from the Object class.
• Dart tools can report two types of problems while coding, warnings
and errors. Warnings are the indication that your code may have some
problem, but it doesn't interrupt the code's execution, whereas error
can prevent the execution of code.
• Dart supports generic types, like List<int>(a list of integers)
or List<dynamic> (a list of objects of any type).
Final And Const Keyword in Dart:
• These keywords are used to define constant variable in Dart i.e. once a
variable is defined using these keyword then its value can’t be
changed in the entire code. These keyword can be used with or
without data type name
• Num a =5;
• Print(num);
• Double d= 4.8;
• Print(d);
• Var v= 3.6;
• Dynamic d = 34;
Syntax for final
// Without datatype
final variable_name
data_type variable_name
Syntax for Const:
// Without datatype
const variable_name
data_type variable_name
Example
void main() {
// Assigning value to geek1 variable without datatype
final geek1 = "Geeks For Geeks";
// Printing variable geek1
print(geek1);
void main() {
// Assigning values
// to the variable
String gfg1 = "Geeks";
String gfg2 = "For";
void main() {
list_name.join("input_string(s)");
• Decision-making statements
• Looping statements
• Jump statements
Flow Statement
of Decision-making statement.
• Dart provides following types If Statement
• If-else Statements
• If else if Statement
• Switch Case Statement
Dart Looping Statements
• Dart looping statements are used to execute the block of code
multiple-times for the given number of time until it matches the given
condition. These statements are also called Iteration statement.
• Dart for loop
• Dart for….in loop
• Dart while loop
• Dart do while loop
Jump Statements
• For loop in Dart is similar to that in Java and also the flow of
execution is the same as that in Java
}
Example
void main()
{
for (int i = 0; i < 5; i++)
{
print('GeeksForGeeks');
}
}
for…in loop
collection.foreach(void f(value))
• f( value): It is used to make a call to the f function for each element in the
collection.
void main() {
var ds = [1,2,3,4,5];
void main()
{
int count = 1;
if (count == 4) {
break;
}
}
print(“sh, you are out of while loop");
}
Dart Collection
• The list is an ordered group of objects where each object is from one
specific type. To define a list in dart, specify the object type inside the
angled brackets (<>) as shown below: