0% found this document useful (0 votes)
3 views38 pages

Introduction to Dart Programming Basics

Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05

Uploaded by

ayboaydo26
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views38 pages

Introduction to Dart Programming Basics

Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05Week05

Uploaded by

ayboaydo26
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BIM493 – Mobile Programming 1

Dart: A Language You Already Know

Prepared

Emin Talip Demirkıran


etd@[Link]
Mobile Programming 1 – Dart: A Language You Already Know

Dart: A Language You Already Know

• At its heart, Dart is a conservative programming


language.
• It was not designed to champion bold new ideas,
but rather to create a predictable and stable
programming environment.
• The language was created at Google in 2011, to
unseat JavaScript as the language of the web.
Mobile Programming 1 – Dart: A Language You Already Know

Dart: A Language You Already Know

• JavaScript is a very flexible language, but its lack of a


type system and misleadingly simple grammar can
make projects very difficult to manage as they grow.
• Dart aimed to fix this by finding a halfway point
between the dynamic nature of JavaScript and the class-
based designs of Java and other object-oriented
languages.
• The language uses a syntax that will be immediately
familiar to any developer who already knows a C-style
language.
Mobile Programming 1 – Dart: A Language You Already Know

Declaring variables – var versus final versus const

• Variables are user-defined symbols that hold a reference to


some value.
• They can range from a single number to large object graphs.
• It is virtually impossible to write a useful program without
at least one variable.
• You can probably argue that almost every program ever
written can be boiled down to taking in some input, storing
that data in a variable, manipulating the data in some way,
and then returning an output.
• All of this would be impossible without variables.
Mobile Programming 1 – Dart: A Language You Already Know

Declaring variables – var versus final versus const

• Recently, a new trend has appeared in programming that


emphasizes immutability.
• This means that once the values are stored in a variable,
that's it – they cannot change. Immutable variables are safer,
produce no side effects, and lead to fewer bugs as a
consequence.

• Dart allows – var, final, and const.


Mobile Programming 1 – Dart: A Language You Already Know

Declaring variables

• The syntax for declaring a mutable variable should look very


similar to other programming languages. First, you declare
the type and then the name of the variable. You can
optionally supply a value for the variable after the
assignment operator. If you don't supply a value, that
variable will be set to null.
Mobile Programming 1 – Dart: A Language You Already Know

Dynamic variables
Mobile Programming 1 – Dart: A Language You Already Know

var keyword
Mobile Programming 1 – Dart: A Language You Already Know

Immutable variables: final & const

• Finally, we have our immutable variables. Dart has two keywords that
can be used to indicate immutability – final and const.
• The main difference between final and const is that const must be
determined at compile time; for example, you cannot have const
containing [Link]() since the current date and time can only
be determined at runtime, not at compile time.
Mobile Programming 1 – Dart: A Language You Already Know

Assignment operator
Mobile Programming 1 – Dart: A Language You Already Know

Assignment operator
Mobile Programming 1 – Dart: A Language You Already Know

type-safe language
Mobile Programming 1 – Dart: A Language You Already Know

final vs const
Mobile Programming 1 – Dart: A Language You Already Know

const is faster
Mobile Programming 1 – Dart: A Language You Already Know

Strings and string interpolation


Mobile Programming 1 – Dart: A Language You Already Know

Strings and string interpolation


Mobile Programming 1 – Dart: A Language You Already Know

Strings and string interpolation


Mobile Programming 1 – Dart: A Language You Already Know

single quote or double quotes


Mobile Programming 1 – Dart: A Language You Already Know

single quote or double quotes


Mobile Programming 1 – Dart: A Language You Already Know

multi-line strings
Mobile Programming 1 – Dart: A Language You Already Know

multi-line strings
Mobile Programming 1 – Dart: A Language You Already Know

$ sign and complex ternary operator


Mobile Programming 1 – Dart: A Language You Already Know

$ sign and complex ternary operator


Mobile Programming 1 – Dart: A Language You Already Know

StringBuffer
Mobile Programming 1 – Dart: A Language You Already Know

functions
Mobile Programming 1 – Dart: A Language You Already Know

functions
Mobile Programming 1 – Dart: A Language You Already Know

functions
Mobile Programming 1 – Dart: A Language You Already Know

functions
Mobile Programming 1 – Dart: A Language You Already Know

functions
Mobile Programming 1 – Dart: A Language You Already Know

functions
Mobile Programming 1 – Dart: A Language You Already Know

functions
Mobile Programming 1 – Dart: A Language You Already Know

functions
Mobile Programming 1 – Dart: A Language You Already Know

How to use functions as variables with closures


Mobile Programming 1 – Dart: A Language You Already Know

Using typedef
Mobile Programming 1 – Dart: A Language You Already Know

Using typedef
Mobile Programming 1 – Dart: A Language You Already Know

Single-line functions using "=>"


Mobile Programming 1 – Dart: A Language You Already Know

Single-line functions using "=>"


Mobile Programming 1 – Dart: A Language You Already Know

Let’s practice

You might also like