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
Make ListView scrollable within PageView #50946
Comments
/cc @Piinks |
Hi @altherat, Flutter determines the priority that widgets receive gesture events like scrolling through a system called the gesture arena. import 'package:flutter/gestures.dart';
void main() {
debugPrintGestureArenaDiagnostics = true;
runApp(App());
} There was some discussion of this in: #28139 (comment) as well as a reference to an article on gestures in Flutter that you may find helpful to achieve the behavior you are looking for. |
Hi @Piinks. I've done a bit of looking at how gestures are handled and have come across those links, but because Even if I did have control, I'm not sure how I would implement the expected behavior because the |
Hi @altherat Have you solved the problem yet? I have the same problem at https://github.com/SunPointed/MPFlutterChart/issues/102. I read this article https://medium.com/flutter-community/combining-multiple-gesturedetectors-in-flutter-26d899d008b2 but use this seem to need maintain all events(tap, longpress, scale etc.), it's too much trouble, is there an easier way for achieve this? |
Hey @SunPointed, Yeah, I hacked up some sort of solution that seems to work but it's not perfect and I haven't tested it too much so it might have problems. I'm not sure if this will work the same with charts. Basically with my solution I manage the vertical scrolling myself by wrapping the entire thing in Here's a sample app demonstrating it. My actual app only needs this ability when it scrolls to the bottom of the list (and not the top) so that's all that I accounted for.
|
@altherat thanks for your answer. I see in my problem I just a Chart provider, I don't know under what circumstances will users use these Charts(I don't know the parent of Chart in the users's view tree). Now I use a GestureArenaTeam to help Chart win in the arena, but this made the chart area not response the PageView. |
@altherat Thanks for idea. I used it in my exploration of scrolling with PageView https://github.com/ra-develop/PageView_test.Flutter.git
void _handleDragUpdate(DragUpdateDetails details) {
if (_activeScrollController == _listScrollController
// && (details.primaryDelta < 0)
&& (_activeScrollController.position.pixels.roundToDouble() >= _activeScrollController.position.maxScrollExtent.roundToDouble()
|| _activeScrollController.position.pixels <0 )) {
_activeScrollController = _pageController;
_drag?.cancel();
_drag = _pageController.position.drag(
DragStartDetails(
globalPosition: details.globalPosition,
localPosition: details.localPosition
),
_disposeDrag
);
}
_drag?.update(details);
} |
I run into this issue as well after a discussion in a Slack group. I think the original poster @altherat has the right idea and the ideal solution would imo also be if there would be some kind of way to tell "There is no way to get the Or if that kind of behavior was just built into the Flutter framework for this kind of gesture/scrolling case. Might be difficult to do implicitly, but there should be some kind of way to tell the framework that you have this kind of case and you want the above mentioned behavior. The work-arounds to implement this kid of behavior that fights how the gesture detection is done by default, get very involved and tedious to implement, so it would be a nice addition if the framework could offer better support for it out of the box. @ra-develop your experimentation looked very interesting and useful to others struggling with this issue. I noticed that the link to it is broken for some reason, I did find it though, so here it is again, hope this link works better: https://github.com/ra-develop/PageView_test.Flutter And all of you following this issue/proposal, show it some love and give it thumbs up! I've heard Google uses up votes as one input in their prioritization. Not sure, can't hurt though! 😀 |
@altherat Thanks a lot for that example. Very helpful. Saved my day. |
@altherat @ra-develop Thanks for ideas. On top of your solution, I checked if the ListView has reached the top and optimized it, here is my solution: judge by the sliding direction, if it slides up to the bottom or down to the top, then next time drag it vertically and let PageController handle it.It worked fine.
|
Thanks for your idea. |
Hi Flutter team, |
I finally solved this problem, here's the solution posted on SO: |
(Triage) I recently came across a few dupes of this issue. This one has the most upvotes, so I am going to close the rest and redirect them here. For reference they are:
I am wondering if the best way to implement this is through ScrollBehaviors. I don't know if we would want a unique ScrollPhysics that will defer on overscroll, or if we could instead introduce an OverscrollBehavior since ScrollPhysics has a lot more to it than just overscroll... not sure, but perhaps bringing everyone to one place from all of these issues will yield better collaboration and feedback. :) |
Container( |
when we place listview within container (may need height) ,listview properly scrollable within page view .(shrinkWrap: true, property of listview must be true) |
Can you share meaningful user facing UI where you'd want this? As a user I think I would find this confusing - what is the expected behavior when you have two axis aligned scrollables in the same plane? |
I can think of one case - e.g. showing a text area that needs to scroll within the list. |
It's the behavior of Android's RecyclerView and ViewPager. |
I can't catch your problem. If your problem is to make proper scrolling
between nested scrollable widgets , you can provide physics as
(physics:AlwaysScrollablePhysics()) of both scrollable view.
…On Thu, 4 Nov 2021, 7:57 am XuanTung95, ***@***.***> wrote:
Can you share meaningful user facing UI where you'd want this?
It's the behavior of Android's RecyclerView and ViewPager.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#50946 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AU7E3N2TNWYAABPAL2ZLUR3UKHVQXANCNFSM4KW2GLJA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
As the description of this ticket, the problem is: if the
Do not seem to work, please provide code if it works for you. |
This SO answer seems to solve the requirement using NotificationListener |
@boris93 This doesn't work when scrolling rapidly. The outside |
What is the property of scrollController or DragUpdateDetails to observe to know when the scrollbar has reached the upper most part of the view. But the scroll is like when a bouncing scroll happens when we scroll a large list and it keeps scrolling smoothly. |
I have uploaded a package: nested_scroll_views, the example and result are as follows. import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:nested_scroll_views/nested_scroll_views.dart';
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
scrollBehavior: const MaterialScrollBehavior().copyWith(
dragDevices: PointerDeviceKind.values.toSet(),
),
home: Scaffold(
appBar: AppBar(title: const Text('nested_scroll_views')),
body: NestedPageView(
wantKeepAlive: true,
scrollDirection: Axis.vertical,
children: <Widget>[
NestedListView.builder(
wantKeepAlive: true,
itemCount: 20,
itemBuilder: (BuildContext context, int index) => ListTile(
title: Text('Item $index'),
),
),
const Text('Page 2'),
],
),
),
);
}
} |
This comment was marked as off-topic.
This comment was marked as off-topic.
hi @Hixie I'm having similar issues with nested scrollable elements. The use of gesture detector and scroll is mandatory in mobile applications. This shouldn't be the natural behavior of scrollable elements in Flutter. This issue reported in 2020 should still not be labeled p3 in 2023. My application feels broken for the end user, so it is not possible for me to publish it. I think it should be in higher priority triage. Is it possible to label it as P1? issue.mp4 |
@ra-develop @altherat Thanks for the solution. The only issue I was facing was when I tried to go up. _activeScrollController.position.pixels <=0 |
@ahmedijaz0007 Well done! Have a nice coding! |
screen-20231122-185955.mp4I want to implement ☝️ this UI, a Vertical-PageView consisting of Vertical ListViews. @dnfield here's an example! @altherat @ra-develop @xiaomanzijia @rydmike thank you very much for your solutions! |
|
Unless I'm missing something, I don't believe it's possible to achieve scrolling on both a
ListView
(orSingleChildScrollView
) and aPageView
when theListView
is within thePageView
and they both scroll in the same direction.Consider the following simple example app with a vertical scrolling
ListView
within a verticalPageView
:There is no way to get the
PageView
to scroll pages. I think expected behavior should be that when theListView
is scrolled to the bottom, thePageView
should then handle the gesture. If I remember correctly, I believe it works like this with Android'sRecyclerView
andViewPager
.I've played around with
ScrollPhysics
,ScrollBehavior
, andNotificationListener
such as listening forOverscrollNotification
and then disabling scrolling forListView
, but I could not find a solution that worked well.The text was updated successfully, but these errors were encountered: