# 未处理的异常: IsolateSpawnException: 反序列化消息失败: 类型 'List<dynamic>' 不是类型 'List<int>' 的子类型

- **ID:** `flutter/isolate-message-deserialization`
- **领域:** flutter
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

在隔离区之间发送消息时，数据必须是可序列化的且具有精确类型；包含混合类型或未类型化列表的 List 在反序列化期间导致类型转换失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Flutter 3.13.0 | active | — | — |
| Flutter 3.22.0 | active | — | — |
| Dart 3.1.0 | active | — | — |

## 解决方案

1. ```
   在发送前显式将列表转换为预期类型。示例：
  List<int> data = [1, 2, 3];
  await isolate.spawn(workerFunction, data);
如果数据来自动态源，使用 'List<int>.from(data)' 确保类型安全。
   ```
2. ```
   使用实现 'toMap' 和 'fromMap' 的类型化数据类进行序列化。示例：
  class MyMessage {
    final List<int> values;
    MyMessage(this.values);
    Map<String, dynamic> toMap() => {'values': values};
    factory MyMessage.fromMap(Map<String, dynamic> map) => MyMessage(List<int>.from(map['values']));
  }
然后发送 map 并在隔离区中反序列化。
   ```
3. ```
   确保使用具体类型参数创建列表，例如 'List<int>.empty(growable: true)' 而不是默认为 List<dynamic> 的 '[]'。
   ```

## 无效尝试

- **Use 'List<dynamic>' as the type for the message variable** — The isolate communication protocol requires concrete types; <dynamic> is not concrete and causes the same error when the receiver expects a specific type. (70% 失败率)
- **Wrap the message in a Map with string keys to bypass type checking** — Maps also require concrete type parameters; a Map<String, dynamic> still fails if the receiver expects Map<String, int>. (60% 失败率)
- **Set '--no-verify-types' flag in the Dart VM** — This flag does not exist; type verification is inherent to the isolate protocol and cannot be disabled. (90% 失败率)
