Dart is a programming language that was developed by Google in 2011. It is an object-oriented language that is designed to be easy to learn and use. Dart is used for building web, mobile, and desktop applications. It is a versatile language that can be used for a wide range of applications.
One of the key features of Dart is its ability to be compiled into JavaScript. This means that developers can write code in Dart and then compile it into JavaScript, which can be run in any modern web browser. This makes it easy to build web applications that are fast and responsive.
Dart also has a strong type system, which helps to catch errors early in the development process. This can save developers a lot of time and effort, as they don’t have to spend as much time debugging their code.
This cheat sheet provides a quick reference for Dart programming language.
Basic Syntax
Syntax
Description
var
Declares a variable
final
Declares a final variable
const
Declares a compile-time constant
if
Conditional statement
else
Executes if the if statement is false
switch
Executes different code blocks based on different conditions
case
A condition in a switch statement
default
Executes if no case condition is true
for
Loops through a block of code a specified number of times
while
Loops through a block of code while a specified condition is true
do-while
Loops through a block of code while a specified condition is true, but at least once
break
Terminates a loop or switch statement
continue
Skips one iteration of a loop
return
Exits a function and returns a value
try-catch
Handles exceptions
throw
Throws an exception
assert
Tests if a condition is true, otherwise throws an exception
Data Types
Data Type
Description
int
Integer
double
Floating-point number
num
Numeric type that can be either int or double
bool
Boolean
String
String of characters
List
Ordered collection of objects
Set
Unordered collection of unique objects
Map
Collection of key-value pairs
dynamic
Type that can be any type
void
No return value
Operators
Operator
Description
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulo
~/
Integer division
++
Increment
--
Decrement
==
Equality
!=
Inequality
>
Greater than
<
Less than
>=
Greater than or equal to
<=
Less than or equal to
&&
Logical AND
||
Logical OR
!
Logical NOT
??
Null-aware operator
?.
Conditional member access
Functions
Syntax
Description
void functionName()
Declares a function with no return value
returnType functionName()
Declares a function with a return value
functionName(parameter1, parameter2)
Declares a function with parameters
functionName({parameter1, parameter2})
Declares a function with named parameters
functionName(parameter1, [parameter2])
Declares a function with optional parameters
functionName() => expression
Declares a function with a single expression
Classes
Syntax
Description
class ClassName
Declares a class
ClassName() {}
Constructor
ClassName.namedConstructor() {}
Named constructor
void methodName()
Declares a method with no return value
returnType methodName()
Declares a method with a return value
get propertyName
Getter
set propertyName
Setter
static methodName()
Static method
static get propertyName
Static getter
static set propertyName
Static setter
extends SuperClass
Inheritance
with Mixin
Mixin
implements Interface
Interface
Asynchronous Programming
Syntax
Description
Future<void> functionName()
Declares an asynchronous function with no return value
Future<returnType> functionName()
Declares an asynchronous function with a return value
await expression
Pauses the execution until the expression is completed