# 类型 'List<dynamic>' 不是类型 'List<String>' 的子类型，在类型转换中

- **ID:** `flutter/invalid-runtime-type-cast`
- **领域:** flutter
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

在未进行显式类型检查的情况下，直接将解码后的 JSON 列表转换为 `List<String>`；JSON 解码返回 `List<dynamic>`。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.17.0 | active | — | — |
| 3.0.0 | active | — | — |
| 3.13.0 | active | — | — |
| 3.22.0 | active | — | — |

## 解决方案

1. ```
   Use `List<String>.from()` or `jsonDecode(data).cast<String>().toList()` to safely convert with type checking.
   ```
2. ```
   Decode with explicit type using `jsonDecode` and then iterate to filter or convert each element.
   ```
3. ```
   Use a JSON serialization library like `json_serializable` with proper model classes to avoid raw casts.
   ```

## 无效尝试

- **** — If any element is not a String, `cast()` throws a runtime error; does not handle mixed types. (30% 失败率)
- **** — Type cast fails at runtime; app crashes when the list is accessed. (50% 失败率)
- **** — Swallows the error but the list remains untyped; subsequent operations may fail silently. (20% 失败率)
