Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReorderableListView inside SingleChildScrollView

I try to use ReorderableListView inside SingleChildScrollView, but I receive a error:

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'

Sample code:

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) {});
  }
}
like image 813
Vitaly Avatar asked Nov 23 '19 11:11

Vitaly


3 Answers

Official Flutter's ReorderableListView is missing a parameter that regular ListView does have and the one you need - shrinkWrap: true. It's a known issue.

Without this parameter, you have to limit its height yourself (for example, wrap it in a Container with fixed height) or remove parent scrollable (SingleChildScrollView).

Or you can use some other reorderable widgets that were made by community - like this one or that one.

like image 193
Igor Kharakhordin Avatar answered Oct 22 '22 23:10

Igor Kharakhordin


in listview give physics like

physics : NeverScrollableScrollPhysics()

it works for me

like image 37
Prashant Vaddoriya Avatar answered Oct 22 '22 23:10

Prashant Vaddoriya


To get a fixed height of a dynamic list you can put it in a Container with the height of yourList.length*HeightOfEachElement.

for example:

    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(...)
like image 45
Elin Avatar answered Oct 22 '22 22:10

Elin