fluttercommunity / flutter-draggable-scrollbar

Draggable Scrollbar - A scrollbar that can be dragged for quickly navigation through a vertical list. Additional option is showing label next to scrollthumb with information about current item. Maintainer: @marica27
https://pub.dev/packages/draggable_scrollbar
MIT License
442 stars 77 forks source link

Error: Cannot get size from a render object that has been marked dirty for layout. #29

Open aidandavis opened 4 years ago

aidandavis commented 4 years ago

Hey, I'm using this widget elsewhere in my app without issues, but I can't work out what's going wrong here. This is the error I get when I scroll:

════════ Exception caught by gesture ═══════════════════════════════════════════
The following assertion was thrown while handling a gesture:
Cannot get size from a render object that has been marked dirty for layout.

The size of this render object is ambiguous because this render object has been modified since it was last laid out, which typically means that the size getter was called too early in the pipeline (e.g., during the build phase) before the framework has determined the size and position of the render objects during layout.

The size getter was called for the following element: DraggableScrollbar
    dirty
    dependencies: [_EffectiveTickerMode]
    state: _DraggableScrollbarState#537cc(tickers: tracking 2 tickers)
The render object from which the size was to be obtained was: _RenderLayoutBuilder#79b83 relayoutBoundary=up1 NEEDS-LAYOUT

Consider using debugPrintMarkNeedsLayoutStacks to determine why the render object in question is dirty, if you did not expect this.

When the exception was thrown, this was the stack
#0      Element.size.<anonymous closure> 
package:flutter/…/widgets/framework.dart:3750
#1      Element.size 
package:flutter/…/widgets/framework.dart:3768
#2      _DraggableScrollbarState.barMaxScrollExtent 
package:draggable_scrollbar/draggable_scrollbar.dart:359
#3      _DraggableScrollbarState.changePosition.<anonymous closure> 
package:draggable_scrollbar/draggable_scrollbar.dart:426
#4      State.setState 
package:flutter/…/widgets/framework.dart:1233
...
Handler: "onUpdate"
Recognizer: VerticalDragGestureRecognizer#245e2
    start behavior: start
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
Cannot get size from a render object that has been marked dirty for layout.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
Cannot get size from a render object that has been marked dirty for layout.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
Cannot get size from a render object that has been marked dirty for layout.
════════════════════════════════════════════════════════════════════════════════
aidandavis commented 4 years ago

I have solved my issue, but I'm not sure it's THE solution. Posting here to aid anyone in future.

I had a ListView.builder() inside the DraggableScrollbar. The ListView had a paramater shrinkwrap, which I had set to true.

I removed it (defaults to false), and no more errors. I guess having it false means that the list size is fixed.

sahmirzali commented 4 years ago

@aidandavis Thanks it's work :)

herrytco commented 1 year ago

I am getting the same error. In my case I am using the Beamerpackage and a LinearPercentIndicator is on a screen which is not currently rendered.

herrytco commented 1 year ago

I am getting the same error. In my case I am using the Beamerpackage and a LinearPercentIndicator is on a screen which is not currently rendered.

I resolved this issue by checking if my widget is currently the top element in the stack (visible) by using the check found in this Stackoverflow Answer:

if (ModalRoute.of(context)?.isCurrent ?? false)
        Padding(
          padding: const EdgeInsets.only(top: 32.0, bottom: 8.0),
          child: LinearPercentIndicator(
            percent: 0.5,
            animation: true,
            lineHeight: 10,
            backgroundColor: Colors.pink,
            padding: EdgeInsets.zero,
            progressColor: Colors.yellow,
            barRadius: const Radius.circular(5),
          ),
        ),