Created
July 26, 2022 18:47
-
-
Save Mufaddal1125/ea69219a8352e7f52ad3d8aba02b39a2 to your computer and use it in GitHub Desktop.
scroll to widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void _scrollToWidget() async { | |
// find the index of fruit to scroll to in fruits | |
// let's scroll to Mandarina | |
final index = fruits.indexOf('Mandarina'); | |
// get global key of Mandarina | |
final key = _fruitKeys[index]; | |
// find the render box of Mandarina | |
var box = key.currentContext?.findRenderObject(); | |
_scrollController.position.ensureVisible( | |
box!, | |
// How far into view the item should be scrolled (between 0 and 1) | |
// with 1 being the bottom of the view and 0 being the top. | |
alignment: 0.2, | |
duration: const Duration(milliseconds: 200), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment