So this listview is dynamically loaded from api, when I scroll on page (up/down) outside of listview it works perfectly, but when I scroll from inside listview I am unable to scroll on the page. Any ideas on what I can change?
It seems you have used Nested ListView.
Just declare:
ScrollController _scrollController = ScrollController();
And call _scrollController to both the properties of contoller in listviews.
I think setting the primary property to false in the listview will solve your problem
Related
Actually, I'm using a Silver AppBar in Flutter and inside it, I'm using a ListView Builder that has its own scroll. So basically there are two scrolls. But when I scroll List View Builder, Silver AppBar doesn't scroll. I want both of them to scroll from anywhere. What do I do?
Use sliver list istead of list view the problem will solve
here is the link of widget : https://api.flutter.dev/flutter/widgets/SliverList-class.html
You can put NeverScrollableScrollPhysics as a scroll physics for ListView.builder, so AppBar will scroll as with the content, maybe this is what you are looking for.
So I have a SingleChildScrollView() whose child is a Column() with different widgets inside it. I have 3 BUTTONS on the app bar. Each for 3 widgets I want to jump to.
When I press the button, I want the UI to automatically scroll to the mapped Widget. Just like we see that effect in websites.
How can I achieve this ?
You can create a ScrollController and pass it to the controller parameter of your scrolling widget. Then you can use the animateTo method to animate to an offset.
Ex.
ScrollController controller = ScrollController();
//In build
SingleChildScrollView(
controller: controller,
child: ...,
)
//In each button onPressed/onTap
controller.animateTo(offset);
I can add ScrollController to a ListView. I was trying to do the same for SliverList but I realized there is no parameter to add a controller. Is there any other way I can achieve this?
Thank you.
You cannot add it to a SliverList, you can however, add the controller to your parent CustomScrollView. The SliverList comes inside the CustomScrollView and should give you the effect you want.
As you can see in the screenshot, you can add a controller to your CustomScrollView
I'm working on a widget that consists of several scrolling widgets (list views and a custom widget). When I scroll any of those list views the custom widget must be scrolled as well. Just to be clear the custom widget isn't actually a scroll view, but a stateful widget that updates its viewport content when a scroll position of the list views is changed.
Currently I'm using a scroll controller for each list and listener to sync the positions by calling jumpTo for the other controllers. But this seems a clumsy way to achieve what I need.
ScrollController exposes the interface to control multiple positions, and because behind the scene it's jumpTo method just calls jumpTo for each ScrollPosition object in positions list, I hoped that there is a way to utilize this for synchronization of multiple scroll views by sharing the same controller. And it seems I'm not the only one who had the same idea (ScrollController attached to multiple scroll views). But the only recommendation I could find is to use a controller per scroll view, which I already do.
Clearly I'm not completely understand how to work with scroll views in Flutter. So my questions are the following. What is the purpose of positions in the ScrollController? What is the design decision behind it and how to use it properly.
If you want to use a single scrollController for many scrollable widgets(ListView,Gridview,etc) the scrollController save each ScrollView in a Iterable so if you want to jumpTo you need to use the argument called positions which is a Iterable<ScrollPosition> type.
Somethin like this:
final _scrollController = ScrollController();
PageView(
controller: _pageController,
children: <Widget>[
_ListView(controller: _scrollController),
_ListView(controller: _scrollController),
_ListView(controller: _scrollController),
],
)
void _moveScroll(){
_scrollController.animateTo(
// ignore: invalid_use_of_protected_member
_scrollController.positions.first.maxScrollExtent,
duration: Duration(milliseconds: 500),
curve: Curves.easeInOut);
}
I have a SingleChildScrollView widget whose child is a Form widget in Flutter. Whenever I made some changes to the radio buttons or switches inside the form and calling setState() method, the view scrolls to the top.
How can I avoid this behavior?
I would recommend passing through a custom ScrollController when constructing your SingleChildScrollView widget.
ScrollController has a property called 'keepScrollOffset' which you need to set to true.
From the documentation at https://docs.flutter.io/flutter/widgets/ScrollController-class.html
keepScrollOffset → bool
Each time a scroll completes, save the current scroll offset with PageStorage and restore it if this controller's scrollable is recreated. [...]
final
I had the same problem after update Flutter SDK version from 2.8.0 to 3.1.0. For me the solution was set a GlobalKey to AlwaysScrollableScrollPhysics.
final GlobalKey scrollKey = GlobalKey();
SingleChildScrollView(physics: AlwaysScrollableScrollPhysics(),key: scrollKey, ...