最佳答案
我试图实现一个非常普遍的行为,现在是有一个水平列表内的另一个小部件,是在同一时间滚动。想象一下 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
作为父元素,在 SliverChildListDelegate
中包含 SliverList
和 List
这些都不起作用,我继续得到同样的错误。这是一件很平常的事情,不应该有什么困难,不知为什么我就是不能让它起作用:
任何帮助都将不胜感激,谢谢!
编辑:
我以为 这个可以帮助我,但它没有。