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. ?
Related
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);
On iOS, tapping the status bar makes PrimaryScrollController go to the top:
https://flutter.dev/docs/resources/platform-adaptations#return-to-top
On iOS, tapping the OS status bar scrolls the primary scroll controller to the top position. There is no equivalent behavior on Android.
My PrimaryScrollController is attached to a ListView with reverse:true, so tapping the status bar makes it scroll to the bottom.
Docs say PrimaryScrollView handles ScrollAction if not handled by another scroll controller.
https://api.flutter.dev/flutter/widgets/PrimaryScrollController-class.html
If a ScrollAction is not handled by an otherwise focused part of the application, the ScrollAction will be evaluated using the scroll view associated with a PrimaryScrollController
How can I handle scroll actions myself so I can reverse the direction PrimaryScrollController goes when the status bar is tapped?
The easiest way to accomplish this is likely going to be reversing the items in your list instead of using the reverse: true flag of ListView.
For example:
ListView(
children: [
Container(),
Container(),
].reversed.toList(),
),
Trying to solve this any other way would get pretty involved. Since we don't have access to the StatusBar we can't override its behavior or listen for taps on it.
I have two Pages inside a vertical PageView.
PageView(
controller: pageController,
scrollDirection: Axis.vertical,
children: [
PageA(),
PageB(),
],
)
The lower page (B) contains the following:
Column
Row
...
Expanded
ListView
Card
Container
Row
...
Flexible
Padding
TextFormField
The problem occurs whenever I focus and unfocus the TextFormField.
Expetation: The Keyboard pops up and the Expanded ListView shrinks, so that the TextFormField is above the Keyboard. When the Keyboard is dismissed, the ListView should expand and the page should look as before.
What happens instead: When the Keyboard is dissmissed, the ListView expands back to its original size but the Page (B) stays offset above where the keyboard was and doesn't move back down. The end result is, that the page (B) is offset upwards ind thus partially offscreen and I have to scroll it manually back down.
The page B itself has a fixed size and once scrolled back down, it can't be offset upwards manually.
TL;DR: PageView pushes page partially off screen after dismissing keyboard.
Any help is apreciated and thanks in advance :D
Edit: Added Screenshot: Before, while and after editing the text field
Edit 2: I think it has something to do with the pageview itself and its scroll physics.
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 have an app that shows textfields and image and I face a problem when the user tries to enter data in textfield as the keyboard goes up and cover the entire textfields.
I tried to use SingleChildScrollView but it is not practical as the textfields do not go up automatically but the user has to scroll up by himself.
Here is the code:
Try using Animation and move up your text field when keyboard appears. Check this out When i select a Textfield the keyboard moves over it
Don't have a sized container inside, follow the below :
SingleChildScrollView(
child: Stack(
children: <Widget>[
... your code
]
)
)
In your Scaffold, set resizeToAvoidBottomPadding property to false.