diff --git a/lib/src/widgets/emoji_picker.dart b/lib/src/widgets/emoji_picker.dart index a20e550..5695a05 100644 --- a/lib/src/widgets/emoji_picker.dart +++ b/lib/src/widgets/emoji_picker.dart @@ -58,7 +58,9 @@ class EmojiPicker extends HookConsumerWidget { ); useEffect(() { - void syncSelectedCategoryWithScroll() { + Future syncSelectedCategoryWithScroll() async { + await WidgetsBinding.instance.endOfFrame; + final viewport = scrollViewKey.currentContext ?.findRenderObject(); if (viewport is! RenderBox) return; @@ -80,14 +82,12 @@ class EmojiPicker extends HookConsumerWidget { selectedCategory.value = selectedIndex; final chipContext = chipKeys[selectedIndex].currentContext; - if (chipContext != null) { - unawaited( - Scrollable.ensureVisible( - chipContext, - duration: Duration(milliseconds: 300), - curve: Curves.easeInOut, - alignment: 0, - ), + if (chipContext != null && chipContext.mounted) { + await Scrollable.ensureVisible( + chipContext, + duration: Duration(milliseconds: 300), + curve: Curves.easeInOut, + alignment: 0, ); } }