# type 'String' is not a subtype of type 'int' in type cast

- **ID:** `flutter/type-error-json-parse-int`
- **Domain:** flutter
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 93%

## Root Cause

A JSON value that is a string (e.g., '123') is being cast directly to int using 'as int' instead of parsing it with int.parse() or using a proper deserialization method.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| flutter 3.13 | active | — | — |
| flutter 3.22 | active | — | — |
| dart 3.2 | active | — | — |
| dart 3.5 | active | — | — |

## Workarounds

1. **Parse the string to int explicitly using int.parse() and handle FormatException for invalid input.** (95% success)
   ```
   Parse the string to int explicitly using int.parse() and handle FormatException for invalid input.
   ```
2. **Use a safe JSON deserialization approach with a fromJson factory that checks the runtime type and converts accordingly.** (90% success)
   ```
   Use a safe JSON deserialization approach with a fromJson factory that checks the runtime type and converts accordingly.
   ```

## Dead Ends

- **Using toString() on the value before casting: (json['id'].toString() as int)** — toString() returns a String, which cannot be cast to int; the error persists. (90% fail)
- **Wrapping in a try-catch without parsing and returning a default value** — The cast still fails; the catch block may mask the root cause and lead to silent data corruption. (70% fail)
