Should I learn the programming language darts

DART tutorial - first steps very practical

The young DART programming language has already gained a foothold, especially in the programming of apps for mobile applications. The company Google has with Flutter a software development kit (SDK) has been set up that uses DART and thus promotes the use and dissemination of this programming language. A major plus is that it deals with it Apps for all mobile operating systems - Apple iOS, Google Android or Microsoft Windows Phone - can be programmed.

Learn to program with DART - our DART tutorial introduces you to the world of Google's programming language with the first steps. This is not so hard. Our advisory article "What is DART?" Offers more about the language itself. For more information, see the article on Google's Flutter software development kit.

The origin of DART

DART originally competed for To overcome weaknesses of JavaScriptwhich, from the point of view of the developer, could no longer be processed within this established programming language.

So began the search for ways to simplify or summarize certain inner logics without losing sight of the variety of possibilities. To give an example: JavaScript has

In DART remains of it:

The first steps with DART

A programming language consists of a world of "vocabulary" with which data is structured and processes (algorithms) are designed. To do this, the language uses a fixed number of terms variablesthat may not be used for any other purpose. Some examples of this are in DART “var”, “int” “if”, “else” or “while”. You can read more details about the architecture of programming languages ​​in our guide to Internet programming languages. The program flow results from the combination of variables, operators, conditions, functions and much more, at the end of which a result is output.

DART very practical

We will present you first and simple, comprehensible examples for learning DART programming, which you can then expand as you wish and with which you can experiment yourself. Every program routine begins with the call of the main function - here using the example of the classic in the code world:

The return type “void” precedes the function “main” and does not return anything. The round brackets “()” Indicate a function there, and within the curly braces "{...}" will be the DARTCode executed - here the command to output something on the screen. What is behind the two Slashes "//" is a commentthat remains invisible; this also works with "/ * this is a multi-line comment ... * /" - known for example from PHP. This allows you to comment on your own code for yourself or other developers in a structured manner, which makes team work on existing projects much easier.

As in Java, C or PHP, all DART statements must be terminated with a semicolon.

You can easily try out the following examples yourself. To do this, use the free open source platform DartPad. This pad has, among other things. the advantage that it numbers the lines of the program and outputs error messages if necessary. In addition, some programming examples are available in a drop-down menu.

In the other code examples in the text, “void main () {…}” is no longer listed.

Define and use variables

Fixed sizes for the program are defined with variables. We start with numbers.

So that's a new one variable "MeineGroesse" has been determined. You became the value Assigned "174". This variable is retained with its value in the program sequence until it is actively changed by operators or functions. To the value of the variables to spend, comes the command "print" in the game.

This results in the following output from lines 3, 6, 9 and 12 in the console using the "print" command in the DartPad:

The Variables in DART take certain Types at. These can be whole numbers (“int”) or floating point numbers (“double”). The variable type "dynamic" can assume different values ​​and expressions in the program sequence. In contrast, blank lines, tabs or paragraphs are not taken into account when the routine is processed. This is why the values ​​are directly below each other in the console on the right.

Trying to assign a wrong value assigning creates a error message with error description in the dart pad:

The designations (identifiers) for the variables used must not contain any keywords. Numbers at the beginning as well as spaces and special characters are not permitted - the underscore "_" and dollar sign "$" are exceptions. The identifiers are case-sensitive and must be unique.

Strings in the DART tutorial

With Strings, the data type "String“(Attention: with a capital S at the beginning), any characters can be processed in DART programming. In this context, you will also learn how to program multi-line formatted lines in DART.

Text is displayed as a string by enclosing the desired content in single or normal quotation marks: 'or ". However, if the text is displayed with quotation marks arranged one behind the other ('' 'or "" ") started and ended, DART also outputs the text at the broken position as a break. This provides an option for formatting the output.

Typographic quotation marks (mostly in the correct English version) can be easily converted into Windows Place in the text with the key combinations [Alt] + 0147 (quotation) and [Alt] + 0148 (lead). These are also output as such in a string by DART. In macOS you can reach these quotation marks with [Alt] + [Shift] + [W] and [Alt] + [2].

Number acrobatics with DART

From the definition of variables the way is not too far too Calculations with variables. Numbers or expressions can be added together. To calculate results, uses DART arithmetic operators. For example, one task could be that an article in the online shop was selected, but the customer three pieces want to buy from it. So in the shopping cart function, the unit price must be multiplied by "3" and the total price must be displayed at the end of the calculation. In the code below you can see the use of different methods for merging data - and the comments in the relevant lines:

There are strings, floating point and integers as well as the Merging of elements of programming to new variables in front. A special feature must be taken into account when merging two existing variables in a new variable for output on the screen: Den already defined variables becomes a in this case Dollar sign "$" (lines 8 and 9 in the above illustration of the dart pad).

Set conditions

When programming, conditions play an important role. Here you will learn how to program a condition with DART. A condition always leads to a decision, in the sense of: If (if) If A occurs, display X appears on the screen; occurs case B (elseif), then the display shows Y; if both do not apply (else), display Z is displayed. With the DART commands shown in brackets, the following code is created:

In the DartPad it looks like this:

Expand your own knowledge in the DART tutorial and replace the word “glove” in the DartPad with “pliers”, “ruler” or “brush” and watch the changes in the programmed output on the console. This can be expanded as required and applied to various cases. For the first time, the operator "||". This double pipe stands for the logical term "or", which is used in DART not as the word "OR" may be used.

You can also go up and down with DART

In order to program the following section, we have to use the so-called Increments and Decrements learn in DART. It is a step-by-step increase or decrease of a starting value. In the example, the number 50 is changed with the operators "++" and "-".

Here you can also see that a simple character string can also be output without a previous definition by inserting it into the program code in round brackets with quotation marks using "print". This is only used here for the optical structuring of the result. With this knowledge you are prepared to program loops.

We're going in circles: loops in DART

Loops are just as important program routines that are needed again and again, for example Compare with existing sizes to employ. The following “formulation” is used for this purpose: We have the value A; change this value until the size (the state) B is reached. As a DART code it looks like this:

What does the dart pad do with it?

In this example one could also use conditions again if, for example, words differ in singular and plural:

To learn to program with DART, copy this code example into the DartPad and change the integer variable “quantity” so that the article “blouse” is output in the singular or in the plural.

DART operators at a glance

You already have a few Operators learned to program in DART. The following table gives you an overview of the most important operators available.

In the table, the "Pattern" variable is set to the value 35.

Operator type description symbol example output
Arithmetic addition + var pattern + 2; 37
  Subtraction - var pattern - 2; 33
  multiplication * var pattern * 3; 105
  division / var pattern / 7; 5
  Integer division ~/ var pattern ~ / 7; 11
  Increase by += var pattern + = 6; 41
  Decrease by -= var pattern - = 7; 28
  Multiplication by *= var pattern * = 2; 70
  Division by /= var pattern / = 7; 5
to compare Identical == var pattern == 35; True
  Not identical != var pattern! = 44; True
  Less than < var pattern <44; true
  Less than or equal to <= var pattern <= 33;  
  Greater than > 44> var pattern; True
  Greater than or equal to >= var pattern> = 23;  
Change Ascending ++ ++ var pattern; 36
  Ascending ++ var pattern ++; 36
  Descending -- --var pattern; 34
  Descending -- var pattern--; 34
  residual value % % var pattern% 3; 2
logic AND && pattern1 && pattern2 … and
  OR ll pattern1 ll pattern2 ... or
  negation ! pattern1! pattern2 … is not
conditions If then ? … : var y = pattern <34? 15:10; 10
  If then ? … : var y = pattern <36? 15:10; 15
  Check for zero ?? var y = pattern ?? 9; 35
  Check for zero ?? var z = 0 ?? template; 35

With this basic knowledge, you can now take further steps in DART, and the way to the project of programming your own app is not quite that far.

Similar articles

Create a native mobile app yourself - Part 2: Programming or app construction kit?

If you want to create a native mobile app yourself, you can do that with a development environment. However, since knowledge of software development is required for this, this variant is usually not an option for beginners. Inexperienced app developers can, however, fall back on special app makers. These do not require any programming knowledge and sometimes score points with a surprising number of ...

Developing Your Own Native Mobile App - Part 3: The Mobile App Design

The design of an application is by no means just determined by shapes and colors - segments of mobile app design such as the positioning of the application content or app usability are at least as important. In the end, the work you put into this will determine whether your app will be used by users at all or whether it will be uninstalled immediately after the download.

Develop your own native mobile app - Part 5.1: Upload an app to the Google Play Store

If you want to upload an app in the Google Play Store, you are about to reach the goal: The Android application is available in the release version and should now land on as many mobile devices as possible. However, adding an app to the official Google app store takes time. Among other things, you need accounts with various Google services in order to have an app on Google Play ...

Flutter Tutorial: How to Develop Apps Using the Google SDK

In recent years, Google has not only published numerous useful services such as Gmail, Maps or Google Workspace, but has also launched various tools for programming software on the market. One of these tools is the Flutter SDK, which is of particular interest to mobile app developers. In the Flutter tutorial below, we show you how to use a simple app ...

Lua tutorial

Perhaps you have already heard of the script language Lua: This language, which originated in Brazil, is used both for game engines and in web servers. As an embedded language, Lua allows programming in a uniform format, completely independent of the respective environment. Lua thus serves as a convenient interface to more complex systems.