Skip to content

Scrollable no-op snapOffsetCallback() fails #6432

Closed

Description

@HansMuller

It should be safe for a snapOffsetCallback() to just return its scrollOffset parameter. This can fail:

Waiting for application to start...
Restart performed in 4331 ms.
I/flutter : ══╡ EXCEPTION CAUGHT BY GESTURE LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter : The following assertion was thrown while routing a pointer event:
I/flutter : 'package:flutter/src/physics/friction_simulation.dart': Failed assertion: line 40 pos 12:
I/flutter : 'startVelocity.abs() >= endVelocity.abs()' is not true.
I/flutter : When the exception was thrown, this was the stack:
I/flutter : #2      FrictionSimulation.FrictionSimulation.through (package:flutter/src/physics/friction_simulation.dart:40:12)
I/flutter : #3      _createSnapScrollSimulation (package:flutter/src/widgets/scroll_behavior.dart:16:14)
I/flutter : #4      OverscrollBehavior.createSnapScrollSimulation (package:flutter/src/widgets/scroll_behavior.dart:257:12)
I/flutter : #5      ScrollableState._createSnapSimulation (package:flutter/src/widgets/scrollable.dart:622:50)
I/flutter : #6      ScrollableState._startToEndAnimation (package:flutter/src/widgets/scrollable.dart:587:19)
I/flutter : #7      ScrollableState.fling (package:flutter/src/widgets/scrollable.dart:564:14)
class AnimationDemo extends StatefulWidget {
  static const String routeName = '/animation';

  @override
  AnimationDemoState createState() => new AnimationDemoState();
}

class AnimationDemoState extends State<AnimationDemo> {
  final GlobalKey<ScrollableState> _scrollableKey = new GlobalKey<ScrollableState>();
  final List<Color> colors = [
    Colors.red[100],
    Colors.red[200],
    Colors.red[300],
    Colors.red[400],
    Colors.red[500],
    Colors.red[600],
  ];

  Widget _createPage(int i) {
    final double pageWidth = MediaQuery.of(context).size.width;
    return new Container(
      decoration: new BoxDecoration(
        backgroundColor: colors[i]
      ),
      child: new SizedBox(
        width: pageWidth,
        child: new Center(
          child: new Text('Page $i'),
        ),
      ),
    );
  }

  double _snapScrollOffset(double flingScrollOffset, Size containerSize) {
    return flingScrollOffset;
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Travel stream'),
      ),
      body: new ScrollableViewport(
        scrollableKey: _scrollableKey,
        scrollDirection: Axis.horizontal,
        snapOffsetCallback: _snapScrollOffset,
        child: new Row(
          children: [0, 1, 2, 3, 4, 5].map(_createPage).toList(),
        ),
      ),
    );
  }
}

Activity

  1. added
    c: regressionIt was better in the past than it is now
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: scrollingViewports, list views, slivers, etc.
    on Oct 20, 2016
  2. Hixie commented on Feb 17, 2017

    @Hixie
    Contributor

    This feature is gone now.

  3. added a commit that references this issue on Oct 4, 2018
  4. github-actions commented on Sep 5, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  5. locked as resolved and limited conversation to collaborators on Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: regressionIt was better in the past than it is nowf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions