Skip to content

Instantly share code, notes, and snippets.

@Mufaddal1125
Created July 26, 2022 18:47
Show Gist options
  • Save Mufaddal1125/ea69219a8352e7f52ad3d8aba02b39a2 to your computer and use it in GitHub Desktop.
Save Mufaddal1125/ea69219a8352e7f52ad3d8aba02b39a2 to your computer and use it in GitHub Desktop.
scroll to widget
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