A Comprehensive Guide For Dart Programming: Crash Course (Part — 1)

Everything you need to know to get started with Dart programming language.

Rajesh Kumar
Level Up Coding
Published in
5 min readJul 11, 2020

--

Most of the time, we spend watching hours of content on youtube or other sites, and all we want is to get started with that language. If you’re going to be a better developer, then you need to learn all the basic concepts, but if you want to build things as fast as possible, then all you need is a crash course.

Why learn Dart programming?

Dart is a relatively simple, modern, and highly efficient programming language. Dart is a client-optimized programming language for apps on multiple platforms. Dart is developed by Google and used to build mobile, desktop, server, and web applications. Dart is an object-oriented, class-based, garbage-collected language with C-style syntax. Dart can compile to either native code or JavaScript.

Topics That We Are Going To Cover in All Parts:

  1. Hello World (All we need to learn programming language 😅)
  2. Comments
  3. Taking Input
  4. Data Types
  5. Operators
  6. Conditional Statements
  7. Loops
  8. Functions
  9. Exception Handling
  10. Collections
  11. Object-Oriented Programming

Topics That We Are Going To Cover in This Part:

  1. Hello World
  2. Comments
  3. Taking Input
  4. Data Types
  5. Operators

1. Hello World:

Main is a special, required, a top-level function where app execution starts. Every app must have a top-level main() function, which serves as the entry point to the app.

So, without wasting time, let’s write our hello world program.

2. Comments

Comment in a program is like a note for all the developer who is going to read that program.

Comments are only for humans at compile time compiler going to ignore it.

3. Taking Input

You can make standard input from the user through the console via the use of the readLineSync() function, and for that, you have to import a library dart:io from the Dart.

4. Data Types

Before diving into data types first, let’s talk about variables.

Variables

Variable is a reference or symbolic name to the memory location of the computer. In simple words, it’s like your primary school’s math equation, e.g., x = 5, where we stored 5 in x. We can change its value according to our needs. For example, we can replace it’s value to x = ‘name’ or whatever we want.

Some rules for declaring variables:

  • Variable can be a combination of letters in lowercase (a to z), uppercase (A to Z), digits (0 to 9), or an underscore (_).
  • A variable cannot start with a digit. 1variable is invalid, but variable1 is perfectly fine.
  • Keywords cannot be used as a Variable name.

Numbers

There are two types of numbers in Dart:

  1. int:

In Dart, values of int can be from -263 to 263–1.

2. double:

64-bit (double-precision) floating-point numbers, as specified by the IEEE 754 standard.

String

A Dart string is a sequence of UTF-16 code units. You can use either single or double quotes to create a string:

You can put the value of expression inside a string by using ${expression}. If the expression is an identifier, you can skip the {}.

Boolean

To represent boolean values, Dart has a type named bool. Only two objects have type bool: the boolean literals true and false

Constants and Final

If you never intend to change a variable, use final or const.

Declaring Variable Dynamically

Variables declared without a static type are implicitly declared as dynamic.

5. Operators:

Arithmetic operators

Dart supports the usual arithmetic operators, as shown in the following example:

Comparison (Relational) operators

Here’s an example of using each of the equality and relational operators:

Logical (Boolean) operators

You can invert or combine boolean expressions using logical operators.

Here’s an example of using logical operators:

Bitwise operators

You can manipulate the individual bits of numbers in Dart. Usually, you’d use these bitwise and shift operators with integers.

Here’s an example of using bitwise and shift operators:

Assignment operators

As you’ve already seen, you can assign values using the = operator. To assign only if the assigned-to variable is null, use the ??= operator.

Compound assignment operators such as += combine operation with an assignment.

The following example uses assignment and compound assignment operators:

Take my advice if you want to be a better developer then work on the initial term of programming because syntax changes in different programming languages, but concepts remain the same. A crash course is designed to help you get started in the dart programming language so you can create your application faster. For better understanding, learn the inner work of that language.

For a better understanding of the time complexity of a program, you can check out our article:

--

--