Python Dart Operators: Arithmetic, Type Test, Ternary & Cascade
Dart features standard arithmetic and logical operators alongside distinctive language enhancements: integer division truncator (`~/`), type testing and smart casting (`is`, `is!`, `as`), ternary operator (`condition ? a : b`), and the powerful cascade operator (`..`) for chaining multiple mutations on a single object.
"The cascade operator (`..`) is like a chef holding a single plate while garnishing, seasoning, and drizzling sauce onto it consecutively without setting the plate down between steps."
Deep Dive: How It Works
Integer Division (`~/`): `7 ~/ 2` returns integer `3` (truncating division) without needing `(7 / 2).toInt()`.
Type Testing & Promotion: `if (obj is String)` automatically promotes `obj` to a `String` within the block (no manual casting needed).
Cascade Operator (`..`): `user..name = "Bob"..age = 25..save();` chains method calls on the same target and returns the original receiver.
Syntax Blueprint
int quotient = 7 ~/ 2; // Integer division (3)
if (value is String) print(value.length); // Smart type promotion
var builder = StringBuffer()
..write("Hello ")
..write("Dart"); // Cascade notationSpecialized operators for division, type promotion, and fluent chaining.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using `as Type` unnecessarily when `is Type` check already promoted the variable.Why it happens: Habit from other languages requiring explicit casting.
How to fix: Trust Dart flow analysis; if guarded by `if (x is String)`, `x` is already a `String`.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Calculate Hours and Minutes with Operators
Given `int totalMinutes = 190;`.
Use `~/` to compute `int h` and `%` to compute `int m`.
Print `${h}h ${m}m`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.