Dart Cheat Sheet

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

SyntaxDescription
varDeclares a variable
finalDeclares a final variable
constDeclares a compile-time constant
ifConditional statement
elseExecutes if the if statement is false
switchExecutes different code blocks based on different conditions
caseA condition in a switch statement
defaultExecutes if no case condition is true
forLoops through a block of code a specified number of times
whileLoops through a block of code while a specified condition is true
do-whileLoops through a block of code while a specified condition is true, but at least once
breakTerminates a loop or switch statement
continueSkips one iteration of a loop
returnExits a function and returns a value
try-catchHandles exceptions
throwThrows an exception
assertTests if a condition is true, otherwise throws an exception

Data Types

Data TypeDescription
intInteger
doubleFloating-point number
numNumeric type that can be either int or double
boolBoolean
StringString of characters
ListOrdered collection of objects
SetUnordered collection of unique objects
MapCollection of key-value pairs
dynamicType that can be any type
voidNo return value

Operators

OperatorDescription
+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

SyntaxDescription
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() => expressionDeclares a function with a single expression

Classes

SyntaxDescription
class ClassNameDeclares 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 propertyNameGetter
set propertyNameSetter
static methodName()Static method
static get propertyNameStatic getter
static set propertyNameStatic setter
extends SuperClassInheritance
with MixinMixin
implements InterfaceInterface

Asynchronous Programming

SyntaxDescription
Future<void> functionName()Declares an asynchronous function with no return value
Future<returnType> functionName()Declares an asynchronous function with a return value
await expressionPauses the execution until the expression is completed
asyncMarks a function as asynchronous

Reference

Dart Documentation