我尝试在ReorderableListView
中使用SingleChildScrollView
,但收到错误消息:
I/flutter ( 9049): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 9049): The following assertion was thrown during performLayout():
I/flutter ( 9049): BoxConstraints forces an infinite height.
I/flutter ( 9049): These invalid constraints were provided to _RenderLayoutBuilder's layout() function by the following
I/flutter ( 9049): function, which probably computed the invalid constraints in question:
I/flutter ( 9049): RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter ( 9049): The offending constraints were:
I/flutter ( 9049): BoxConstraints(w=360.0, h=Infinity)
I/flutter ( 9049): User-created ancestor of the error-causing widget was:
I/flutter ( 9049): ReorderableListView file:///Users/vvv/Documents/Projects/WorkoutBook/lib/main.dart:43:12
I/flutter ( 9049): When the exception was thrown, this was the stack:
I/flutter ( 9049): #0 BoxConstraints.debugAssertIsValid.<anonymous closure>.throwError (package:flutter/src/rendering/box.dart:501:9)
I/flutter ( 9049): #1 BoxConstraints.debugAssertIsValid.<anonymous closure> (package:flutter/src/rendering/box.dart:548:21)
I/flutter ( 9049): #2 BoxConstraints.debugAssertIsValid (package:flutter/src/rendering/box.dart:552:6)
I/flutter ( 9049): #3 RenderObject.layout (package:flutter/src/rendering/object.dart:1618:24)
I/flutter ( 9049): #4 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter ( 9049): #5 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #6 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #7 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #8 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:744:15)
I/flutter ( 9049): #9 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #10 _RenderSingleChildViewport.performLayout (package:flutter/src/widgets/single_child_scroll_view.dart:497:13)
I/flutter ( 9049): #11 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #12 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #13 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #14 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #15 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #16 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #17 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #18 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #19 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #20 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #21 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #22 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #23 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #24 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #25 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #26 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #27 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #28 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #29 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #30 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
I/flutter ( 9049): #31 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:444:7)
I/flutter ( 9049): #32 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
I/flutter ( 9049): #33 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
I/flutter ( 9049): #34 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #35 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #36 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #37 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #38 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1232:11)
I/flutter ( 9049): #39 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #40 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #41 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #42 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #43 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #44 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #45 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #46 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #47 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #48 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #49 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #50 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #51 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #52 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #53 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #54 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #55 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3140:13)
I/flutter ( 9049): #56 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #57 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter ( 9049): #58 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #59 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #60 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #61 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #62 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #63 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #64 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #65 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #66 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #67 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #68 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #69 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 9049): #70 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter ( 9049): #71 RenderView.performLayout (package:flutter/src/rendering/view.dart:152:13)
I/flutter ( 9049): #72 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1578:7)
I/flutter ( 9049): #73 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:844:18)
I/flutter ( 9049): #74 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:341:19)
I/flutter ( 9049): #75 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:761:13)
I/flutter ( 9049): #76 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:280:5)
I/flutter ( 9049): #77 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1033:15)
I/flutter ( 9049): #78 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:975:9)
I/flutter ( 9049): #79 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:784:7)
I/flutter ( 9049): #88 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
I/flutter ( 9049): #89 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
I/flutter ( 9049): #90 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
I/flutter ( 9049): (elided 8 frames from package dart:async and package dart:async-patch)
I/flutter ( 9049): The following RenderObject was being processed when the exception was fired: RenderStack#68003 relayoutBoundary=up13 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
I/flutter ( 9049): creator: Stack ← _Theatre ← Overlay-[GlobalKey#e1f76 ReorderableListView overlay key] ←
I/flutter ( 9049): ReorderableListView ← NestedGroup ← Column ← _SingleChildViewport ←
I/flutter ( 9049): IgnorePointer-[GlobalKey#25797] ← Semantics ← _PointerListener ← Listener ← _GestureSemantics ← ⋯
I/flutter ( 9049): parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
I/flutter ( 9049): constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=Infinity)
I/flutter ( 9049): size: MISSING
I/flutter ( 9049): alignment: AlignmentDirectional.topStart
I/flutter ( 9049): textDirection: ltr
I/flutter ( 9049): fit: expand
I/flutter ( 9049): overflow: clip
I/flutter ( 9049): This RenderObject had the following child:
I/flutter ( 9049): child 1: _RenderLayoutBuilder#718b7 NEEDS-LAYOUT NEEDS-PAINT
RenderBox was not laid out: RenderStack#68003 relayoutBoundary=up13 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1681 pos 12: 'hasSize'
示例代码:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(),
body: Test(),
),
);
}
}
class Test extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: <Widget>[Text('Scrollable Header'), NestedGroup()],
),
);
}
}
class NestedGroup extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ReorderableListView(
children: List.generate(
10,
(position) => ListTile(
key: ValueKey(position),
title: Text("Dragable item $position"))),
onReorder: (d, dfd) {});
}
}
答案 0 :(得分:1)
要获得动态列表的固定高度,您可以将其放入具有 yourList.length*HeightOfEachElement 高度的容器中。
例如:
Container(
/*If you don't the height to be bigger than the height of your screen
use MediaQuery.of(context).size.height.
You can add a -200 to the end if you don't want it to take up the whole
screen*/
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height,
),
/*If each of the elements you are creating are 65 pixels high which sort
of fits a card widget or something similar...*/
height: yourList.length * 65.0,
child: ListView.builder(...)
答案 1 :(得分:0)
Official Flutter的ReorderableListView
缺少常规ListView
确实需要的参数以及您需要的参数-shrinkWrap: true
。这是known issue。
没有此参数,您必须自己限制其高度(例如,将其包装在具有固定高度的 Container 中)或删除父级可滚动显示的内容( SingleChildScrollView )。 / p>
答案 2 :(得分:0)
它现在对我来说没有问题,你可以试试这个例子,将两个 ReorderableListView 嵌套到(也适用于 ReorderableListView.builder)SingleChildScrollView,另外你也可以嵌套在其他小部件中,正如你从文本示例中看到的那样。< /p>
很难将 ReorderableListView 嵌套到 ListView 中,发现它有效并将其张贴在这里,因为它与 op 问题有关
import 'package:flutter/material.dart';
/// This is the main application widget.
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
final List<int> _items = List<int>.generate(10, (int index) => index);
final List<int> _items2 = List<int>.generate(15, (int index2) => index2);
@override
Widget build(BuildContext context) {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final Color oddItemColor = colorScheme.primary.withOpacity(0.05);
final Color evenItemColor = colorScheme.primary.withOpacity(0.15);
int index = 0;
int index2 = 0;
return Scaffold(
appBar: AppBar(
title: Text('Example'),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
ListTile(title: Text('test 1')),
ListTile(title: Text('test 2')),
ReorderableListView(
physics: ClampingScrollPhysics(),
shrinkWrap: true,
padding: const EdgeInsets.symmetric(horizontal: 40),
children: <Widget>[
for (index = 0; index < _items.length; index++)
ListTile(
key: Key('$index'),
tileColor:
_items[index].isOdd ? oddItemColor : evenItemColor,
title: Text('Item ${_items[index]}'),
),
],
onReorder: (int oldIndex, int newIndex) {
setState(() {
if (oldIndex < newIndex) {
newIndex -= 1;
}
final int item = _items.removeAt(oldIndex);
_items.insert(newIndex, item);
});
},
),
ListTile(title: Text('test 3')),
ListTile(title: Text('test 4')),
ReorderableListView(
physics: ClampingScrollPhysics(),
shrinkWrap: true,
padding: const EdgeInsets.symmetric(horizontal: 40),
children: <Widget>[
for (index2 = 0; index2 < _items2.length; index2++)
ListTile(
key: Key('$index2'),
tileColor:
_items2[index2].isOdd ? oddItemColor : evenItemColor,
title: Text('Item ${_items2[index2]}'),
),
],
onReorder: (int oldIndex2, int newIndex2) {
setState(() {
if (oldIndex2 < newIndex2) {
newIndex2 -= 1;
}
final int item = _items2.removeAt(oldIndex2);
_items2.insert(newIndex2, item);
});
},
),
ListTile(title: Text('test 5')),
ListTile(title: Text('test 6')),
],
),
),
);
}
}
答案 3 :(得分:0)
我遇到了同样的问题,我搜索了所有内容,发现 ReorderableListView 在 Column 和/或 SingleChildScrollView 中不起作用,但是您可以在 ReorderableListView 的 header 属性中使用 Column 来组装您的界面。
答案 4 :(得分:0)
在列表视图中给出物理效果
physics : NeverScrollableScrollPhysics()
它对我有用