GithubHelp home page GithubHelp logo

Using [ScrollablePositionedList] will report an error: 'minScrollExtent <= maxScrollExtent': is not true. about flutter.widgets HOT 6 OPEN

arcticfox1919 avatar arcticfox1919 commented on August 23, 2024
Using [ScrollablePositionedList] will report an error: 'minScrollExtent <= maxScrollExtent': is not true.

from flutter.widgets.

Comments (6)

arcticfox1919 avatar arcticfox1919 commented on August 23, 2024

I don't know if it is related to the following code

Timer.periodic(const Duration(milliseconds: 1000), (time) {
      ...............
        dataList.add(item);

         itemScrollController.jumpTo(
              index: dataList.length - 1, alignment: 0.8);
        }
    });

from flutter.widgets.

tarobins avatar tarobins commented on August 23, 2024

Issue shows up if the content is too short to scroll to the desired location:

import 'package:flutter/material.dart';
import 'package:flutter_widgets/flutter_widgets.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  ItemScrollController itemScrollController = ItemScrollController();

  void jumpEnd() {
    itemScrollController.jumpTo(index: 1, alignment: 0.8);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
          child: ScrollablePositionedList.builder(
        itemCount: 2,
        itemBuilder: (context, index) => ConstrainedBox(
          constraints: BoxConstraints.tightFor(height: 200),
          child: Text(
            'Item $index',
            style: TextStyle(fontSize: 36),
          ),
        ),
        itemScrollController: itemScrollController,
      )),
      floatingActionButton: FloatingActionButton(
        onPressed: jumpEnd,
        tooltip: 'Jump',
        child: Icon(Icons.airline_seat_recline_normal),
      ),
    );
  }
}

Clicking on button results in


════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
'package:flutter/src/widgets/scroll_position.dart': Failed assertion: line 457 pos 14: 'minScrollExtent <= maxScrollExtent': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

User-created ancestor of the error-causing widget was: 
  ScrollablePositionedList file:///Users/tarobins/scratch/min_max/lib/main.dart:42:43
When the exception was thrown, this was the stack: 
#2      ScrollPosition.applyContentDimensions (package:flutter/src/widgets/scroll_position.dart:457:14)
#3      UnboundedRenderViewport.performLayout (package:flutter_widgets/src/scrollable_positioned_list/src/viewport.dart:140:20)
#4      RenderObject.layout (package:flutter/src/rendering/object.dart:1716:7)
#5      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
#6      RenderObject.layout (package:flutter/src/rendering/object.dart:1716:7)
...
The following RenderObject was being processed when the exception was fired: UnboundedRenderViewport#4e0b8 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...  needs compositing
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=603.4)
...  layer: OffsetLayer#6d6d5
...    offset: Offset(0.0, 0.0)
...  size: Size(411.4, 603.4)
...  axisDirection: down
...  crossAxisDirection: right
...  offset: ScrollPositionWithSingleContext#ce2dd(offset: 0.0, range: 0.0..0.0, viewport: 603.4, ScrollableState, ClampingScrollPhysics, IdleScrollActivity#02106, ScrollDirection.idle)
...  anchor: 0.8
RenderObject: UnboundedRenderViewport#4e0b8 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  needs compositing
  parentData: <none> (can use size)
  constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=603.4)
  layer: OffsetLayer#6d6d5
    offset: Offset(0.0, 0.0)
  size: Size(411.4, 603.4)
  axisDirection: down
  crossAxisDirection: right
  offset: ScrollPositionWithSingleContext#ce2dd(offset: 0.0, range: 0.0..0.0, viewport: 603.4, ScrollableState, ClampingScrollPhysics, IdleScrollActivity#02106, ScrollDirection.idle)
  anchor: 0.8
...  child -1: RenderSliverPadding#ec516 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    needs compositing
...    parentData: paintOffset=Offset(0.0, 282.7) (can use size)
...    constraints: SliverConstraints(AxisDirection.down, GrowthDirection.reverse, ScrollDirection.idle, scrollOffset: 0.0, remainingPaintExtent: 482.7, crossAxisExtent: 411.4, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 603.4, remainingCacheExtent: 1689.6 cacheOrigin: 0.0 )
...    geometry: SliverGeometry(scrollExtent: 200.0, paintExtent: 200.0, maxPaintExtent: 200.0, cacheExtent: 200.0)
...      scrollExtent: 200.0
...      paintExtent: 200.0
...      maxPaintExtent: 200.0
...      cacheExtent: 200.0
...    padding: EdgeInsets.zero
...    textDirection: ltr
...    child: RenderSliverList#b7836 relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: paintOffset=Offset(0.0, 0.0) (can use size)
...      constraints: SliverConstraints(AxisDirection.down, GrowthDirection.reverse, ScrollDirection.idle, scrollOffset: 0.0, remainingPaintExtent: 482.7, crossAxisExtent: 411.4, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 603.4, remainingCacheExtent: 1689.6 cacheOrigin: 0.0 )
...      geometry: SliverGeometry(scrollExtent: 200.0, paintExtent: 200.0, maxPaintExtent: 200.0, cacheExtent: 200.0)
...        scrollExtent: 200.0
...        paintExtent: 200.0
...        maxPaintExtent: 200.0
...        cacheExtent: 200.0
...      currently live children: 0 to 0
...      child with index 0: RenderRepaintBoundary#fbb7e relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: index=0; layoutOffset=0.0 (can use size)
...        constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
...        layer: OffsetLayer#53138
...          offset: Offset(0.0, 282.7)
...        size: Size(411.4, 200.0)
...        metrics: 0.0% useful (1 bad vs 0 good)
...        diagnosis: insufficient data to draw conclusion (less than five repaints)
...        child: RenderIndexedSemantics#65d31 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: <none> (can use size)
...          constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
...          semantic boundary
...          size: Size(411.4, 200.0)
...          index: 0
...  center child: RenderSliverPadding#c91fc relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    needs compositing
...    parentData: paintOffset=Offset(0.0, 482.7) (can use size)
...    constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.idle, scrollOffset: 0.0, remainingPaintExtent: 120.7, crossAxisExtent: 411.4, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 603.4, remainingCacheExtent: 1327.5 cacheOrigin: 0.0 )
...    geometry: SliverGeometry(scrollExtent: 200.0, paintExtent: 120.7, maxPaintExtent: 200.0, hasVisualOverflow: true, cacheExtent: 200.0)
...      scrollExtent: 200.0
...      paintExtent: 120.7
...      maxPaintExtent: 200.0
...      hasVisualOverflow: true
...      cacheExtent: 200.0
...    padding: EdgeInsets.zero
...    textDirection: ltr
...    child: RenderSliverList#0a718 relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: paintOffset=Offset(0.0, 0.0) (can use size)
...      constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.idle, scrollOffset: 0.0, remainingPaintExtent: 120.7, crossAxisExtent: 411.4, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 603.4, remainingCacheExtent: 1327.5 cacheOrigin: 0.0 )
...      geometry: SliverGeometry(scrollExtent: 200.0, paintExtent: 120.7, maxPaintExtent: 200.0, hasVisualOverflow: true, cacheExtent: 200.0)
...        scrollExtent: 200.0
...        paintExtent: 120.7
...        maxPaintExtent: 200.0
...        hasVisualOverflow: true
...        cacheExtent: 200.0
...      currently live children: 0 to 0
...      child with index 0: RenderRepaintBoundary#1e8f7 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: index=0; layoutOffset=0.0 (can use size)
...        constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
...        layer: OffsetLayer#eacbb
...          offset: Offset(0.0, 482.7)
...        size: Size(411.4, 200.0)
...        metrics: 0.0% useful (1 bad vs 0 good)
...        diagnosis: insufficient data to draw conclusion (less than five repaints)
...        child: RenderIndexedSemantics#c3c35 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: <none> (can use size)
...          constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
...          semantic boundary
...          size: Size(411.4, 200.0)
...          index: 1
...  child 1: RenderSliverPadding#1b8af relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    parentData: paintOffset=Offset(0.0, 682.7) (can use size)
...    constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.idle, scrollOffset: 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 411.4, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 603.4, remainingCacheExtent: 1127.5 cacheOrigin: 0.0 )
...    geometry: SliverGeometry(scrollExtent: 0.0, hidden, maxPaintExtent: 0.0)
...      scrollExtent: 0.0
...      hidden
...      maxPaintExtent: 0.0
...    padding: EdgeInsets.zero
...    textDirection: ltr
...    child: RenderSliverList#57043 relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: paintOffset=Offset(0.0, 0.0) (can use size)
...      constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.idle, scrollOffset: 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 411.4, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 603.4, remainingCacheExtent: 1127.5 cacheOrigin: 0.0 )
...      geometry: SliverGeometry(scrollExtent: 0.0, hidden, maxPaintExtent: 0.0)
...        scrollExtent: 0.0
...        hidden
...        maxPaintExtent: 0.0
...      no children current live
════════════════════════════════════════════════════════════════════════════════════════════════════

from flutter.widgets.

tarobins avatar tarobins commented on August 23, 2024

I should probably make the list bounce using whatever physics are set when the user scrolls too far.

from flutter.widgets.

marcglasberg avatar marcglasberg commented on August 23, 2024

@tarobins I'm also getting this a lot. I believe solving this issue should get some priority, since you can't really know if it the content is too short or not. So there's no work around for this one.

However, bouncing back (animating) is not the correct behavior. As I said, when you jump to some item you can't really know if it the content is too short or not, so you will get what seems to be "random" bounces. It's even worse if, say, you're jumping from top to bottom, but you overshoot and then it bounces from bottom to top, which is very disorienting since the user will think it somehow moved to the opposite direction.

What it should do, instead, is just jump instantly to the resting position (the position it would settle if a bouncing back would occur).

from flutter.widgets.

tarobins avatar tarobins commented on August 23, 2024

I've written a doc that proposes a solution to this bug and a few other. If you are interested in the solution to this bug, please take a look and leave comments.

https://docs.google.com/document/d/1ozIndwAbYcd96ktOX8LnsZ1L-K08q2XvdDD3G_ruEE8/edit#

from flutter.widgets.

marcglasberg avatar marcglasberg commented on August 23, 2024

@tarobins Added my comments there already.

from flutter.widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.