> ## 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 Typed Variable

A typed variable in Dart represents a named memory allocation strictly bound to a specific data type during compile-time. Because Dart utilizes a sound static type system, once a variable is bound to a type—either through explicit declaration or analyzer type inference—it cannot be reassigned to a value of a non-subtype, guaranteeing type safety at runtime.

## Syntax

```dart theme={"dark"}
// Explicit non-nullable type declaration
Type identifier = expression;

// Explicit nullable type declaration
Type? identifier = expression;

// Type inference (statically typed via the initializer)
var identifier = expression;
```

## Type Declaration Mechanisms

Dart provides multiple mechanisms for establishing a variable's type:

**1. Explicit Typing**
The developer explicitly defines the data type preceding the variable identifier. The compiler enforces this type strictly.

```dart theme={"dark"}
int counter = 0;
String identifier = "System_01";
bool isActive = true;
```

**2. Type Inference**
Using the `var`, `final`, or `const` keywords without an explicit type annotation instructs the Dart analyzer to infer the static type based on the initialization value. The variable remains strictly typed.

```dart theme={"dark"}
var threshold = 10.5;      // Statically inferred as double
final username = "admin";  // Statically inferred as String
const maxRetries = 3;      // Statically inferred as int
```

**3. Dynamic Typing (Type System Opt-Out)**
The `dynamic` keyword explicitly disables static type checking for a variable, deferring type resolution to runtime. This allows the variable to hold values of any type and change types during execution.

```dart theme={"dark"}
dynamic payload = "Initial String";
payload = 404; // Valid at runtime
```

## Sound Null Safety

Dart's type system distinguishes between nullable and non-nullable types. By default, all typed variables are non-nullable and must be initialized before use.

To declare a variable that can legally hold a `null` value, the type annotation must be suffixed with a question mark (`?`).

```dart theme={"dark"}
// Non-nullable (cannot hold null)
String sessionToken = "abc-123";

// Nullable (can hold a String or null)
String? optionalParameter = null;
```

## Generics in Typed Collections

When declaring typed variables for collections, Dart uses generics (`<T>`) to enforce the type of the elements contained within the collection.

```dart theme={"dark"}
// Explicitly typed List containing integers
List<int> byteStream = [0, 1, 1, 0];

// Explicitly typed Map with String keys and dynamic values
Map<String, dynamic> jsonPayload = {
  "id": 101,
  "status": "active"
};
```

<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>
