我直接在一个列中使用FutureBuilder
中的Expanded
小部件,一切都很好,但是添加一个RefreshIndicator
小部件似乎破坏了一些东西,我不明白为什么。
return Scaffold(
body: Column(
children: [
Row(...),
FutureBuilder(
future: ...,
builder: (context, snapshot) {
return RefreshIndicator(
onRefresh: ...,
child: getList(snapshot.connectionState, user),
);
},
),
],
),
);
Widget getList(ConnectionState connectionState, UserRepository user) {
switch (connectionState) {
case ConnectionState.done:
return Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: number,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: ...,
child: Card(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
...,
Expanded(
child: Container(
padding: ...,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"",
softWrap: false,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
Text(
"",
softWrap: false,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 14),
),
],
),
),
),
],
),
),
);
},
),
);
default:
return const Text("other");
}
}
错误:
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type StackParentData.
Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a Stack widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
_ScrollSemantics-[GlobalKey#85a8f] ← NotificationListener<ScrollMetricsNotification> ← Scrollable ← PrimaryScrollController ← ListView ← Expanded ← NotificationListener<OverscrollIndicatorNotification> ← NotificationListener<ScrollNotification> ← Stack ← RefreshIndicator ← ⋯
我看过其他有类似错误的帖子,他们只是谈论使用列内展开,我已经在做了,所以我迷路了。我试图让我的列表视图是屏幕的剩余高度,这是工作之前添加RefreshIndicator
。
1条答案
按热度按时间bd1hkmkf1#
我找到了一个解决办法,尽管我确信这是最好的办法。
我删除了直接围绕
ListView
的Expanded
,并在FutureBuilder
内部添加了一个Column
和两个Expanded
。