Comments (22)
itemPositionsListener.itemPositions.addListener(() {
if (itemPositionsListener.itemPositions.value.last.index > (dataList.length - 3)) {
// do your logic
}
});
from flutter.widgets.
Yes please something like this
_controller = ScrollController();
_controller.addListener(_scrollListener);
from flutter.widgets.
@tarobins
I also need this feature because I want to be able to click a button to go back to the top of the list.
Thank you very much for providing the plug-in and look forward to your reply.
Because I want to realize it as soon as possible, can you provide me with a method?
from flutter.widgets.
If currentMax
is the index of the last item currently in the list, I think something like
needToPaginate = itemPositionsListener.itemPositions.value.firstWhere(
(ItemPosition position) => position.index == currentMax, orElse: () => null)
?.itemTrailingEdge <= 1.0 ?? false;
Haven't tested, not sure if it even compiles, but something like that should work.
from flutter.widgets.
Just attach the ScrollablePositionedList with NotificationListener and calculate the progress -> double progress = notification.metrics.pixels /
notification.metrics.maxScrollExtent;
from flutter.widgets.
Sorry the docs are wrong and I'll correct them, but I think you should be able to do
itemPositionsListener.itemPositions.addListener((positions) => ...);
let me know if that doesn't work. I'll update the docs and investigate a bit more.
[edit]
ohhhh sorry, my mistake, you'll need to do something like
itemPositionsListener.itemPositions.addListener(() {
doSomethingWith(itemPositionsListener.itemPositions.value);
});
I'll update the docs.
from flutter.widgets.
If
currentMax
is the index of the last item currently in the list, I think something likeneedToPaginate = itemPositionsListener.itemPositions.value.firstWhere( (ItemPosition position) => position.index == currentMax, orElse: () => null) ?.itemTrailingEdge <= 1.0 ?? false;
Haven't tested, not sure if it even compiles, but something like that should work.
can you elaborate this @tarobins?
itemTrailingEdge <=
is always null
i want to know how to detect whether its reach top or bottom in the list
thanks.
from flutter.widgets.
This works for detecting pixel offset 0.0:
_itemPositionsListener.itemPositions.addListener(() {
final positions = _itemPositionsListener.itemPositions.value;
final firstPosition = positions.first;
final elevated = firstPosition.index != 0 || firstPosition.itemLeadingEdge != 0;
if (_inputBoxElevated != elevated) {
setState(() {
_inputBoxElevated = elevated;
});
}
});
from flutter.widgets.
you can expose the frontScrollController to use it as "_controller"
from flutter.widgets.
Can you explain a bit more of what you're looking for? Do you mean the pixel offset of the scroll?
from flutter.widgets.
you can expose the frontScrollController to use it as "_controller"
How would you expose it without modifying the package? I am trying to use this widget with a widget from another package that requires the default ScrollController as a parameter. It seems like the ScrollablePositionedList uses a ScrollController internally, I just don't understand why is it not exposed by default..?
from flutter.widgets.
@tarobins in README.md
it says you can see which items are on screen, but that code doesn't work:
itemPositionsListener.positions.addListener((positions) => ...);
The correct code is
itemPositionsListener.positions.itemPositions.addListener(() => ...);
So, you can no longer see the index of the items on screen. Why was that modified/removed? We need to see which index is being shown on screen in order to trigger a listener
from flutter.widgets.
@Clear2 sorry, so an issue with exposing the scroll offset is that there's isn't a consistent scroll offset when you jump around the list. For example, if you jump to item 1000, we don't figure out the offset off 1000, we just create a new list with 1000 at offset 0 and display that list.
I could possibly expose an interface that give a relative offset as scrolls are occurring.
If you still need this, could you explain some more about your use case?
from flutter.widgets.
@tarobins Hi, I have one use case: for threaded comments lists (like Reddit, Hacker News, etc), I want to add a feature that can collapse comments between a selected one and its parent. After collapsing, it should keep the exact selected comment item's position for a better user experience. So it requires both the position index and offset. Thanks for this great widget.
from flutter.widgets.
"I also need this feature because I want to be able to click a button to go back to the top of the list."
That should already be doable.
itemScrollController.jumpTo(index: 0);
from flutter.widgets.
@tarobins This issue is impossible to solve. As you said, the scroll offset isn't a consistent scroll offset when you jump around the list.
However, yes, it would be useful to expose an interface that gives a relative offset as scrolls are occurring. This is useful, for example, to show some effects like scrollbars, shadows, or collapsing appbars. In fact, I just implemented something like this so that I can show these kinds of effects. What I did is this:
Create a ScrollPosition
where:
minScrollExtent
is 0
maxScrollExtent
is 1000 * itemCount
;
pixels
:
- Make it the correct pixels value when the first item is in the cache. Because in this situation you can calculate the pixels precisely.
- Make it
1000 * itemCount - pixelsToEnd
when the last item is in the cache. Because in this sittuation you can calculate the pixelsToEnd precisely. And calculated like this it will be compatible withmaxScrollExtent
. - For all the other situations, make it
1000 * minItem
whereminItem
is the minimum index in the screen at the moment. This will give some good approximation to our current position in relation tomaxScrollExtent
.
The docs should state that these positions are approximate, and meant only to help with scrollbars, shadows, and collapsing appbars.
from flutter.widgets.
How do we know when user has scrolled all the way to the top or bottom of screen in order to trigger a function that will load more items hence pagination?
Using itemPositionsListener.itemPositions.value does not seem to provide any information on when index is at zero or end of list.
from flutter.widgets.
I think I figured it out using
ValueListenableBuilder<Iterable>(
valueListenable: itemPositionsListener.itemPositions,...
the max and min values can be compared to the index of the list displayed
from flutter.widgets.
@tarobins This issue is impossible to solve. As you said, the scroll offset isn't a consistent scroll offset when you jump around the list.
However, yes, it would be useful to expose an interface that gives a relative offset as scrolls are occurring. This is useful, for example, to show some effects like scrollbars, shadows, or collapsing appbars. In fact, I just implemented something like this so that I can show these kinds of effects. What I did is this:
Create a
ScrollPosition
where:
minScrollExtent
is0
maxScrollExtent
is1000 * itemCount
;
pixels
:
- Make it the correct pixels value when the first item is in the cache. Because in this situation you can calculate the pixels precisely.
- Make it
1000 * itemCount - pixelsToEnd
when the last item is in the cache. Because in this sittuation you can calculate the pixelsToEnd precisely. And calculated like this it will be compatible withmaxScrollExtent
.- For all the other situations, make it
1000 * minItem
whereminItem
is the minimum index in the screen at the moment. This will give some good approximation to our current position in relation tomaxScrollExtent
.The docs should state that these positions are approximate, and meant only to help with scrollbars, shadows, and collapsing appbars.
Do you have a small example with what you did? (Repo / Gist)
Where are you doing the ScrollPosition creation and those calculations?
from flutter.widgets.
how do you observe the offset now?Any solution????
from flutter.widgets.
https://pub.dev/packages/scrollable_positioned_list_extended see here
from flutter.widgets.
Added a method for observing scroll offset changes in #472 and #473. Please let me know how this works and if more is needed.
from flutter.widgets.
Related Issues (20)
- ItemScrollController attached HOT 1
- VisibilityDetector fires event unexpectedly HOT 1
- [ScrollablePositionedList] Scrollbar unexpected jumping HOT 2
- [scrollable_positioned_list]: add jumpTo method to ScrollOffsetController
- [ScrollablePositionedList] PageStorage cast bug
- [ScrollablePositionedList] with StickyHeader
- Unsupported operation: add
- Twitchy scroll animation
- Inconsistent Expansion Direction of AnimatedContainer in ScrollablePositionedList
- [visibility_detector] Incorrect Visibility info Bug after updating to 4.0.0 or later
- A RenderViewport exceeded its maximum number of layout cycles
- R
- RTL support scrollable_positioned_list HOT 1
- Allow or expose scroll controller to be used outside.
- [visibility_detector] onVisibilityChanged not works when scroll faster HOT 5
- Flutter_simple_treeview: could not configure tree node height
- flutter simple tree: lazy build subtree nodes
- [ScrollablePositionedList] Inactive Package
- [visibility_detector] iOS swipe back - Unexpected visibleFraction behaviour. It is just 1.0 or 0.0.
- Use webview load pie charts on ios platform will show blank page in first load, and changed reloadAfterInit to true have blow error.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter.widgets.