Created
February 5, 2020 07:04
-
-
Save kitoko552/52ad2f137c45be1823c0205673f66c8b to your computer and use it in GitHub Desktop.
This file contains 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 controller = ScrollController(); | |
final globalKey = GlobalKey(); | |
ListView.builder( | |
controller: controller, | |
itemBuilder: (context, index) { | |
return SomeWidget( | |
key: globalKey, | |
child: child, | |
); | |
}, | |
); | |
// スクロール処理 | |
final context = globalKey.currentContext; | |
if (context == null) { | |
// globalKeyを設定したWidgetが描画範囲外ならnullになる | |
return; | |
} | |
final RenderBox renderBox = context.findRenderObject(); | |
final offset = box.localToGlobal(Offset.zero).distance; | |
controller.animateTo(offset); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment