wait for end of frame before highlighting categories

Fixes an issue where category highlights could be one scroll old
This commit is contained in:
Henry Hiles 2026-09-17 12:01:23 -04:00
commit 072a366f43
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -58,7 +58,9 @@ class EmojiPicker extends HookConsumerWidget {
); );
useEffect(() { useEffect(() {
void syncSelectedCategoryWithScroll() { Future<void> syncSelectedCategoryWithScroll() async {
await WidgetsBinding.instance.endOfFrame;
final viewport = scrollViewKey.currentContext final viewport = scrollViewKey.currentContext
?.findRenderObject(); ?.findRenderObject();
if (viewport is! RenderBox) return; if (viewport is! RenderBox) return;
@ -80,14 +82,12 @@ class EmojiPicker extends HookConsumerWidget {
selectedCategory.value = selectedIndex; selectedCategory.value = selectedIndex;
final chipContext = chipKeys[selectedIndex].currentContext; final chipContext = chipKeys[selectedIndex].currentContext;
if (chipContext != null) { if (chipContext != null && chipContext.mounted) {
unawaited( await Scrollable.ensureVisible(
Scrollable.ensureVisible(
chipContext, chipContext,
duration: Duration(milliseconds: 300), duration: Duration(milliseconds: 300),
curve: Curves.easeInOut, curve: Curves.easeInOut,
alignment: 0, alignment: 0,
),
); );
} }
} }