# 断言失败：'verticalDirection' 为 null 或未设置

- **ID:** `flutter/assertion-failed-vertical-viewport`
- **领域:** flutter
- **类别:** assertion_error
- **验证级别:** ai_generated
- **修复率:** 93%

## 根因

垂直视口（例如 ListView、Column）在没有指定约束高度的情况下使用，导致无限垂直空间。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Flutter 3.13 | active | — | — |
| Flutter 3.16 | active | — | — |
| Flutter 3.19 | active | — | — |

## 解决方案

1. ```
   Wrap the ListView in a Container or SizedBox with a fixed height:
SizedBox(
  height: 300,
  child: ListView(
    children: [...],
  ),
)
   ```
2. ```
   If inside a Column, wrap the ListView in an Expanded and ensure the Column has a bounded height (e.g., by wrapping the Column in a SizedBox or Expanded):
Column(
  children: [
    Expanded(
      child: ListView(children: [...]),
    ),
  ],
)
   ```
3. ```
   Use a CustomScrollView with slivers if you need mixed scrolling and non-scrolling content.
   ```

## 无效尝试

- **Wrapping the ListView in an Expanded widget inside a Column** — Expanded only works when the parent has a fixed height; if the Column itself is unbounded, it still fails. (40% 失败率)
- **Setting shrinkWrap: true on the ListView without also constraining the parent** — ShrinkWrap only affects the viewport's own size calculation; the parent widget must still provide a finite height constraint. (30% 失败率)
- **Using Flexible instead of Expanded** — Flexible also requires a bounded parent; same fundamental issue. (50% 失败率)
