From 072a366f43536593a40ad82e26044195885e33d0 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Thu, 17 Sep 2026 12:01:23 -0400 Subject: [PATCH] wait for end of frame before highlighting categories Fixes an issue where category highlights could be one scroll old --- lib/src/widgets/emoji_picker.dart | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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, ); } }