【问题标题】:ListView is not showing nested inside Row and ColumnListView 未显示嵌套在行和列中
【发布时间】:2022-11-28 04:13:41
【问题描述】:

我想知道为什么我把 ListView 的内容放在 Column 里面的 Row 里看不到? 谢谢

`

body: Center(
  child: Column(
    children: <Widget>[
      Row(
        children: <Widget>[
          Flexible(
            child: ListView(
              children: [
                Text('Text 1'),
                Text('Text 2'),
              ],
            ),
          ),
        ],
      ),
    ],
  ),
),

`

我确实将 ListView 放在 Flexible 中,但它不起作用。

【问题讨论】:

  • 您是否尝试在 ListView 中将 AxisDirection 更改为水平

标签: flutter dart


【解决方案1】:

如果你运行你的代码,你会看到这个错误:

Vertical viewport was given unbounded height.

这意味着高度不受限制。

你应该设置shrinkWrap

scrollDirection 中滚动视图的范围是否应该是 由正在查看的内容决定。

如果滚动视图不收缩包装,则滚动视图将 扩展到 scrollDirection 中允许的最大大小。如果 滚动视图在 scrollDirection 中有无限约束,然后 shrinkWrap 必须为真。

true

ListView(
  shrinkWrap: true,
   children: [
   Text('Text 1'),
   Text('Text 2'),
    ],
)
import 'package:flutter/material.dart';

const Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
      ),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  Flexible(
                    child: ListView(
                      shrinkWrap: true,
                      children: [
                        Text('Text 1'),
                        Text('Text 2'),
                      ],
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

【讨论】:

    猜你喜欢
    • 2021-10-19
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 2019-12-11
    相关资源
    最近更新 更多