scroll-to-index icon indicating copy to clipboard operation
scroll-to-index copied to clipboard

Unhandled Exception: Cannot get renderObject of inactive element.

Open Rolewong6 opened this issue 2 years ago • 1 comments

  1. Firstly, the lastest version of this packages can not run below Flutter 3.0.
  2. And, it can't jump to the listview item, which showed previoulsy then be inactive in a long listview.builder. The exception meessage is under below.

Can you help make it still available on Flutter 2.x and give me some suggestion on question 2.

[VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: Cannot get renderObject of inactive element. In order for an element to have a valid renderObject, it must be active, which means it is part of the tree. Instead, this element is in the _ElementLifecycle.inactive state. If you called this method from a State object, consider guarding it with State.mounted. The findRenderObject() method was called for the following element: AutoScrollTag-[<1480198977>] #0 Element.findRenderObject. (package:flutter/src/widgets/framework.dart:4039:9) #1 Element.findRenderObject (package:flutter/src/widgets/framework.dart:4052:6) #2 AutoScrollControllerMixin._offsetToRevealInViewport (package:scroll_to_index/scroll_to_index.dart:478:27) #3 AutoScrollControllerMixin._forecastMoveUnit (package:scroll_to_index/scroll_to_index.dart:380:11) #4 AutoScrollControllerMixin._scrollToIndex (package:scroll_to_index/scroll_to_index.dart:271:13)

Rolewong6 avatar Jun 06 '22 03:06 Rolewong6

You can set cacheExtent of ListView.Builder to big number to fix problem number 2.

e.g.:

ListView.builder(
                cacheExtent: 10000,
...
              ),

Timu5 avatar Aug 30 '22 15:08 Timu5