【发布时间】:2019-06-27 23:01:20
【问题描述】:
我现在正在尝试实现一种非常常见的行为,即在另一个小部件中同时具有可滚动的水平列表。想想像 IMDb 应用程序的主屏幕:
所以我想要一个可以垂直滚动的小部件,上面有很少的项目。在它的顶部,应该有一个水平的ListView,然后是一些名为motivationCard 的项目。列表和卡片之间也有一些标题。
我在我的Widget 上得到了类似的东西:
@override
Widget build(BuildContext context) => BlocBuilder<HomeEvent, HomeState>(
bloc: _homeBloc,
builder: (BuildContext context, HomeState state) => Scaffold(
appBar: AppBar(),
body: Column(
children: <Widget>[
Text(
Strings.dailyTasks,
),
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: tasks.length,
itemBuilder: (BuildContext context, int index) =>
taskCard(
taskNumber: index + 1,
taskTotal: tasks.length,
task: tasks[index],
),
),
Text(
Strings.motivations,
),
motivationCard(
motivation: Motivation(
title: 'Motivation 1',
description:
'this is a description of the motivation'),
),
motivationCard(
motivation: Motivation(
title: 'Motivation 2',
description:
'this is a description of the motivation'),
),
motivationCard(
motivation: Motivation(
title: 'Motivation 3',
description:
'this is a description of the motivation'),
),
],
),
),
);
这是我得到的错误:
I/flutter (23780): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (23780): The following assertion was thrown during performResize():
I/flutter (23780): Horizontal viewport was given unbounded height.
I/flutter (23780): Viewports expand in the cross axis to fill their container and constrain their children to match
I/flutter (23780): their extent in the cross axis. In this case, a horizontal viewport was given an unlimited amount of
I/flutter (23780): vertical space in which to expand.
我试过了:
-
用
Expanded小部件包装 ListView -
用
SingleChildScrollView > ConstrainedBox > IntrinsicHeight包裹列 -
将
CustomScrollView作为父级,SliverList和SliverChildListDelegate内的列表
这些都不起作用,我继续遇到同样的错误。这是一件很常见的事情,应该不难,不知怎的,我就是无法让它工作:(
任何帮助将不胜感激,谢谢!
编辑:
我认为this 可以帮助我,但它没有。
【问题讨论】:
-
你的垂直 ListView 在哪里?
-
没有垂直的ListView。我希望整个屏幕都可以滚动。想想一个列,但可滚动。然后在该列中,我希望有一个水平滚动的 ListView。该列中的其余子项将是不同的项目,即标题、卡片和其他。
标签: flutter listview flutter-layout horizontal-scrolling vertical-scrolling