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(() {
void syncSelectedCategoryWithScroll() {
Future<void> 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(
if (chipContext != null && chipContext.mounted) {
await Scrollable.ensureVisible(
chipContext,
duration: Duration(milliseconds: 300),
curve: Curves.easeInOut,
alignment: 0,
),
);
}
}