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);
Related
I want to make it responsive like if I move the slider then correspondent list which is below should be highlighted and should move according to the slider.
I have tried PageView controller to pass in ListView controller but it never worked.
I want to create this login form with Flutter:
and I think the easiest way would be to have a
Form( ...
ListView( ....
[Login Card]
[Social Card]
[Register Card]));
but for that it should only be possible to scroll thought this listview with this two(or 4) buttons not with the fingers, and the buttons automatically navigate to the very bottom or very top. Is there a way to do this with a ListView with a ScrollController e.g. ?
I am making an app that has a BottomNavigationBar with 3 items, the first one is the Home page and it contains a ListView of items.
What i want to do is make the ListView scroll back to top when the Home button in the BottomNavigationBar is pressed.
Is there a way to do so?
initiate ScrollController for ListView
use onTap from BottomNavigationBar and get the current index
in onTap func, determine index == 0 and scrollController.jumpTo(0.0);
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.
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);
}