> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart Addition

The `+` operator in Dart is a binary, left-associative additive operator used for arithmetic addition and object concatenation. Architecturally, Dart implements operators as instance methods. When the expression `a + b` is evaluated, the Dart compiler resolves it as an invocation of the `+` method defined on the left operand's class, passing the right operand as the single argument.

## Syntax and Resolution

```dart theme={"dark"}
operand1 + operand2;
```

Because the operation is resolved against the left operand's class definition, the type of the right operand must satisfy the parameter type defined by the left operand's `operator +` signature.

## Type-Specific Behaviors

**Numeric Types (`int`, `double`, `num`)**
When applied to numeric types, the operator performs standard arithmetic addition. Dart enforces type promotion rules during this operation:

* `int + int` returns an `int`.
* `double + double` returns a `double`.
* `int + double` (or vice versa) promotes the `int` to a `double` and returns a `double`.

```dart theme={"dark"}
int a = 5;
double b = 2.5;
Type resultType = (a + b).runtimeType; // double
```

**Strings (`String`)**
When invoked on a `String`, the operator performs concatenation, returning a new `String` allocated in memory. Dart is strictly typed regarding string concatenation; the right operand **must** also be a `String`. Implicit coercion of non-string types does not occur.

```dart theme={"dark"}
String s1 = "Hello";
String s2 = " World";
String s3 = s1 + s2; 

// String s4 = s1 + 5; // Compile-time error: The argument type 'int' can't be assigned to the parameter type 'String'.
```

**Lists (`List<E>`)**
When applied to `List` objects, the `+` operator returns a new `List<E>` containing all elements from the left list followed by all elements from the right list. Both operands must be lists, and their generic types must be compatible.

```dart theme={"dark"}
List<int> list1 = [1, 2];
List<int> list2 = [3, 4];
List<int> combined = list1 + list2; // [1, 2, 3, 4]
```

## Operator Overloading

Developers can define the `+` operator for custom classes using the `operator` keyword. The method must take exactly one parameter (the right operand) and should ideally return a new instance of an object rather than mutating the existing instance, adhering to expected value-type semantics.

```dart theme={"dark"}
class Vector {
  final int x;
  final int y;

  const Vector(this.x, this.y);

  // Overriding the + operator
  Vector operator +(Vector other) {
    return Vector(this.x + other.x, this.y + other.y);
  }
}

Vector v1 = Vector(1, 2);
Vector v2 = Vector(3, 4);
Vector v3 = v1 + v2; // Resolves to Vector(4, 6)
```

## Precedence and Associativity

* **Associativity:** Left-to-right. An expression like `a + b + c` is evaluated as `(a + b) + c`.
* **Precedence:** The `+` operator sits at the "Additive" precedence level. It is evaluated *after* Multiplicative operators (`*`, `/`, `~/`, `%`) and *before* Shift operators (`<<`, `>>`, `>>>`) and Relational operators (`<`, `>`, `<=`, `>=`).

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
