# AssertionError: 'file:///...' 不是有效的 URI

- **ID:** `flutter/invalid-uri-assertion`
- **领域:** flutter
- **类别:** assertion_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

在构造 Uri 对象时使用了格式错误的 URI 字符串（例如缺少方案或双斜杠）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.0.0 | active | — | — |
| 3.7.0 | active | — | — |
| 3.16.0 | active | — | — |

## 解决方案

1. ```
   Use Uri.file() to create file URIs correctly from a file path.
   ```
2. ```
   Validate and sanitize the URI string before parsing with Uri.parse().
   ```
3. ```
   Use path_provider to get correct paths and then convert to URI.
   ```

## 无效尝试

- **** — Does not address the root cause of missing or malformed scheme (e.g., 'file:///path' vs 'file:///C:/path'). (40% 失败率)
- **** — Uri.parse requires absolute URIs; relative paths cause assertion errors. (35% 失败率)
- **** — Without a scheme, the URI is invalid; the platform may misinterpret the path. (25% 失败率)
