HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to DartVariablesData TypesOperatorsStringsListsConditions (if / else)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 List & Map
🔀 Condition & Loop
🧩 Function
Dart›Operators

Operators

Math (+ - * / ~/ %), comparison (== != < >), and logical (&& || !) operators.

Simple enough for a 5-year-old to understand

Math operators

/ always returns a decimal (double). Use ~/ for integer division. % gives the remainder.

Example code
1
void main() {
2
print(7 + 3);
10
Output / Input10
3
print(7 / 2);
3.5 (always decimal)
Output / Input3.5 (always decimal)
4
print(7 ~/ 2);
3 (integer division)
Output / Input3 (integer division)
5
print(7 % 2);
1 (remainder)
Output / Input1 (remainder)
6
}
Output / Input
💡 Hint: ~/ is integer division; / always returns a double.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.Which one is integer division in Dart (without dropping the decimal)?
2.Print the remainder of dividing 23 by 4.

🎯 Expected output: 3

Loading editor…

About this topic

Dart's operators are mostly familiar from the C family: arithmetic, comparison, and logical operators work as expected. Logical operators short-circuit, meaning if the left side determines the result, the right side is never evaluated.

A few Dart-specific operators are worth learning. The integer division operator yields an integer result. The null-coalescing operator uses the right-hand value if the left-hand one is null. The null-assignment operator, on the other hand, assigns only when the variable is null.

The cascade operator is Dart's most notable convenience: it spares you from typing the object repeatedly when performing consecutive operations on the same object. It is frequently encountered in Flutter code and significantly shortens the code.

What you will learn

  • Arithmetic and comparison operators
  • The integer division operator
  • The null-coalescing and null-assignment operators
  • The safe navigation operator
  • The cascade operator

Who is this for?

  • Beginners who have learned basic syntax
  • Those learning null-handling methods
  • Those curious about cascade notation in Flutter code

When to use?

The null-coalescing operator is the shortest way to provide a default value for missing fields coming from the server.

If you are going to create an object and configure a few settings on it, the cascade operator eliminates the need for intermediate variables.

Common mistakes

Wrong

void main() {
  print(10 / 3);
  print((10 / 3).runtimeType);
}

There is no error here, but the expectation might be wrong: the result is 3.3333333333333335, not 3, and its type is double. Those coming from Java or C expect integer division. If you want an integer result in Dart, you must use the separate operator.

Correct

void main() {
  print(10 ~/ 3);
  print((10 ~/ 3).runtimeType);
}

Wrong

void main() {
  String? ad;
  String gosterim = ad;
  print(gosterim);
}

A nullable value cannot be assigned directly to a non-nullable variable; you get the error "A value of type 'String?' can't be assigned to a variable of type 'String'". You need to guarantee the type by providing a fallback value.

Correct

void main() {
  String? ad;
  String gosterim = ad ?? "guest";
  print(gosterim);
}

Wrong

void main() {
  int sayac = 0;
  if (sayac = 1) {
    print("one");
  }
}

A single equals sign is for assignment, and comparison is done with a double equals sign. Since Dart mandates that conditions be of type bool, this code fails to compile and the error is immediately visible. In languages like C, the same syntax runs silently and leads to hard-to-find bugs.

Correct

void main() {
  int sayac = 0;
  if (sayac == 1) {
    print("one");
  }
}

Frequently asked questions

What does the null-assignment operator do?

It assigns the value on the right if the variable is null, and does nothing if it is not null. It is the shortest way to assign a default value and carries no risk of accidentally overwriting the existing value.

How exactly does the cascade operator work?

It ignores the result of each call and returns the object itself. Thus, you can chain method calls on the same object. It even works on methods that don't return the object itself—that is the difference.

Which operator is available for exponentiation?

There is no exponentiation operator in Dart; the pow function from the math library is used. Multiplying a number by itself to square it is both faster and more readable.

Summary

A single slash produces a double, while a tilde and a slash produce an integer.

The null-coalescing operator provides a fallback value.

The null-assignment operator assigns only when null.

Conditions must be of type bool.

The cascade operator performs consecutive operations on the same object.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code