Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got NaN exception when first time scrolling to beginning or end of list #173

Closed
JmyW opened this issue Sep 15, 2020 · 11 comments
Closed

Got NaN exception when first time scrolling to beginning or end of list #173

JmyW opened this issue Sep 15, 2020 · 11 comments
Assignees
Labels
p: scrollable_positioned_list Related to package:scrollable_positioned_list SPL-bounds issues ScrollablePositonedList problems with list positioning when go outside the bounds of the list SPL-scroll to end

Comments

@JmyW
Copy link

JmyW commented Sep 15, 2020

It's happened the following exception at first time scrolling to beginning or end of list.

Steps:

  1. When scroll list is appeared.
  2. Swipe right to scroll to the beginning of list
    or Swipe left to scroll to the end of list
  3. Got the following NaN exception

════════ Exception caught by scheduler library ═════════════════════════════════════════════════════
The following UnsupportedError was thrown during a scheduler callback:
Unsupported operation: Infinity or NaN toInt

When the exception was thrown, this was the stack:
#0 double.toInt (dart:core-patch/double.dart:192:36)
#1 double.round (dart:core-patch/double.dart:160:34)
#2 _PositionedListState._schedulePositionNotificationUpdate. (package:scrollable_positioned_list/src/positioned_list.dart:334:26)
#3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1116:15)
#4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1063:9)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

@JmyW
Copy link
Author

JmyW commented Sep 15, 2020

I am using "scrollable_positioned_list: ^0.1.7"

@jamesderlin jamesderlin added p: scrollable_positioned_list Related to package:scrollable_positioned_list SPL-bounds issues ScrollablePositonedList problems with list positioning when go outside the bounds of the list SPL-scroll to end labels Sep 18, 2020
@tarobins tarobins self-assigned this Oct 7, 2020
@mig35
Copy link

mig35 commented Oct 7, 2020

Hey @JmyW and @tarobins ,

I had the same problem in my project and was able to fix this in this PR (#180), but then I tried to reproduce this issue in the sample to create a test of this fix, but was not able to do this.
My project is really complex and I'm not able to find the real reason why it happens in my and not the sample example.

@JmyW can you share your reproduce example or at least test my fix in your project?
You can install it by modifying the dependency like this:

  scrollable_positioned_list:
    git:
      url: https://github.com/mig35/flutter.widgets
      ref: bugfix/173
      path: packages/scrollable_positioned_list

@JmyW
Copy link
Author

JmyW commented Oct 7, 2020

It's weird, I took 3 hours tried previous version I did backup. I cannot reproduce it any more.
In last two weeks, I keep growing up my program, I did not remembered I've ever seen it in past two weeks. Since your request, I rollback to my backup codes, it is also unduplicated. I even tried to write a new program with the scrolling, but same.

I'm sorry I couldn't confirm it for you.

@justkawal
Copy link

@JmyW I thinks that the issue is in package : scrollable_positioned_list

@shushper
Copy link

shushper commented Oct 9, 2020

I have the same issue. Version 0.1.8.

Steps:

  1. Scroll to position with itemScrollController.jumpTo(index: itemPosition)
  2. Scroll list with a finger.
The following UnsupportedError was thrown during a scheduler callback:
Unsupported operation: Infinity or NaN toInt

When the exception was thrown, this was the stack: 
#0      double.toInt (dart:core-patch/double.dart:192:36)
#1      double.round (dart:core-patch/double.dart:160:34)
#2      _PositionedListState._schedulePositionNotificationUpdate.<anonymous closure> (package:scrollable_positioned_list/src/positioned_list.dart:324:45)
#3      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
#4      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1063:9)

@justkawal
Copy link

which version of scrollable_positioned_list u r using ?

@JmyW
Copy link
Author

JmyW commented Oct 10, 2020

I used 0.1.7 for issue creation and retest with same version, no change.

@JmyW
Copy link
Author

JmyW commented Oct 10, 2020

I used 0.1.7 for issue creation and retest with same version, no change.

Oops, I think you were asking @shushper

@mig35
Copy link

mig35 commented Oct 11, 2020

Also @shushper could you check if my fix work as described here: #173 (comment)

@shushper
Copy link

@justkawal I am using a 0.1.8 version.

@mig35 Yes, your fix works because I made the same fix by myself and it helped.

The reason for the issue is that through the computation of itemOffset in _schedulePositionNotificationUpdate method of _PositionedListState class value of itemOffset becomes NaN. I added some logs and found that the problem in the reveal variable.

if (widget.scrollDirection == Axis.vertical) {
  final reveal = viewport.getOffsetToReveal(box, 0).offset;
  final itemOffset = reveal -
      viewport.offset.pixels +
      viewport.anchor * viewport.size.height;

  print('Reveal = $reveal');
  print('Viewport Offset = ${viewport.offset.pixels}');
  print('Viewport Anchor = ${viewport.anchor}');
  print('Viewport height = ${viewport.size.height}');
  print('Item offset = $itemOffset');

  positions.add(ItemPosition(
      index: key.value,
      itemLeadingEdge: itemOffset.round() /
          scrollController.position.viewportDimension,
      itemTrailingEdge: (itemOffset + box.size.height).round() /
          scrollController.position.viewportDimension));
 
}

When the issue occurs my logs are:

I/flutter (10988): Reveal = NaN
I/flutter (10988): Viewport Offset = 757.1581221883587
I/flutter (10988): Viewport Anchor = 0.14921465968586387
I/flutter (10988): Viewport height = 764.0

So it seems like we should prevent the reveal from being NaN or check its value before the computation of itemOffsets

@tarobins
Copy link
Collaborator

Does someone have a public project where this can be repo'd? I've been trying with this one https://github.com/tarobins/spl_example_wrapper but no luck yet.

asjqkkkk pushed a commit to asjqkkkk/flutter.widgets that referenced this issue May 8, 2021
@asjqkkkk asjqkkkk mentioned this issue May 8, 2021
4 tasks
asjqkkkk added a commit to asjqkkkk/flutter.widgets that referenced this issue May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: scrollable_positioned_list Related to package:scrollable_positioned_list SPL-bounds issues ScrollablePositonedList problems with list positioning when go outside the bounds of the list SPL-scroll to end
Projects
None yet
Development

No branches or pull requests

6 participants