gpt4 book ai didi

flutter - 可重新排序 ListView : Exception: BoxConstraints forces an infinite height

转载 作者:IT王子 更新时间:2023-10-29 06:46:27 25 4
gpt4 key购买 nike

TL;DR - 如何实现 shrinkWrap = trueReorderableListView ?

我试图创建一个 ReoderableListViewColumn<-Container作为 parent ,发生了这个错误。

I/flutter (32618): The following assertion was thrown during performLayout():
I/flutter (32618): BoxConstraints forces an infinite height.


I/flutter (32618): The following RenderObject was being processed when the exception was fired: RenderStack#23840 relayoutBoundary=up17 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
I/flutter (32618): creator: Stack ← _Theatre ← Overlay-[GlobalKey#dc153 ReorderableListView overlay key] ←
I/flutter (32618): ReorderableListView ← StreamBuilder<QuerySnapshot> ← Column ← Padding ← Padding ← Container ←
I/flutter (32618): BoardCard ← Column ← _SingleChildViewport ← ⋯
I/flutter (32618): parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
I/flutter (32618): constraints: BoxConstraints(0.0<=w<=328.0, 0.0<=h<=Infinity)
I/flutter (32618): size: MISSING
I/flutter (32618): alignment: AlignmentDirectional.topStart
I/flutter (32618): textDirection: ltr
I/flutter (32618): fit: expand
I/flutter (32618): overflow: clip
I/flutter (32618): This This RenderObject had the following child:
I/flutter (32618): child 1: _RenderLayoutBuilder#55d3d NEEDS-LAYOUT NEEDS-PAINT

如果它是 ListView,这将很容易修复通过使用 shrinkWrap = true但是ReorderableListView没有这个属性。

这是代码

@override
Widget build(BuildContext context) {
final _listTitleStyle =
TextStyle(fontSize: 20, fontWeight: FontWeight.w500);
final _listSubTitleStyle = TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
color: Color(0xff7D7373),
);
return Container(
padding: EdgeInsets.all(8),
margin: EdgeInsets.all(8),
child: Column(
children: <Widget>[
Container(
child: Row(
children: <Widget>[
Expanded(
child: Row(
textBaseline: TextBaseline.alphabetic,
crossAxisAlignment: CrossAxisAlignment.baseline,
children: <Widget>[
Text(
widget.cardTitle,
style: _listTitleStyle,
),
SizedBox(
width: 2,
),
Text(
widget.cardSubTitle,
style: _listSubTitleStyle,
),
],
),
),
Icon(Icons.keyboard_arrow_down),
],
),
),
SizedBox(
height: 8,
),
StreamBuilder<QuerySnapshot>(
stream: widget.query,
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
return _buildList(context, snapshot.data.documents);
}),
],
),
);
}

Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
snapshot.forEach((snap) {
print("debug 1 ${snap.data}");
print(TodoItem.fromSnapshot(snap, snap.reference).toString());
});
return ReorderableListView(
onReorder: (oldIndex, newIndex){},
children: snapshot
.map((data) => TodoTile(TodoItem.fromSnapshot(data, data.reference), key: UniqueKey(),))
.toList(),
);
}

最佳答案

我已通过将 ReorderableListView 替换为包 flutter_reorderable_list 来解决此问题, 它接受一个 child (Widget) 不像 ReorderableListView 接受 child (List)

它的实现有点复杂。你可以看看example了解如何正确实现它。

关于flutter - 可重新排序 ListView : Exception: BoxConstraints forces an infinite height,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56714040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com