Last active
July 26, 2022 18:41
-
-
Save Mufaddal1125/8d3116f92d9433cedd6416f6ee42c943 to your computer and use it in GitHub Desktop.
create scrollcontroller
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
final _scrollController = ScrollController(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: ListView.builder( | |
// assign scroll controller to list view | |
controller: _scrollController, | |
itemBuilder: (context, index) { | |
return ListTile( | |
// assign key to each item | |
key: _fruitKeys[index], | |
title: Text(fruits[index]), | |
); | |
}, | |
itemCount: fruits.length, | |
), | |
), | |
floatingActionButton: FloatingActionButton.extended( | |
tooltip: 'Scroll to Mandarina', | |
onPressed: _scrollToWidget, | |
label: const Text('Scroll to Mandarina'), | |
icon: const Icon(Icons.arrow_upward_rounded), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment