fix performance issues with new emoji picker

This commit is contained in:
Henry Hiles 2026-09-16 11:41:11 -04:00
commit 3af38e615e
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -14,118 +14,114 @@ final class const EmojiPicker({
super.key,
}) extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) => Container(
padding: .symmetric(horizontal: 16),
constraints: .loose(.new(500, 700)),
child: ref
.watch(EmojiController.provider)
.betterWhen(
data: (categories) {
final combined = categories.addAll(extraCategories);
Widget build(BuildContext context, WidgetRef ref) {
final selectedCategory = useState<int?>(null);
final scrollController = useScrollController();
final listController = useMemoized(ListController.new);
return HookBuilder(
builder: (context) {
final selectedCategory = useState<int?>(null);
final scrollController = useScrollController();
final listController = useMemoized(ListController.new);
useEffect(() {
void onChange() {
final range = listController.visibleRange;
if (range != null) {
final firstVisible = range.$1;
if (selectedCategory.value != firstVisible) {
WidgetsBinding.instance.addPostFrameCallback((_) {
selectedCategory.value = firstVisible;
});
}
}
}
useEffect(() {
void onChange() {
final range = listController.visibleRange;
if (range != null) {
final firstVisible = range.$1;
if (selectedCategory.value != firstVisible) {
WidgetsBinding.instance.addPostFrameCallback((_) {
selectedCategory.value = firstVisible;
});
}
}
}
listController.addListener(onChange);
return () => listController.removeListener(onChange);
}, [listController]);
listController.addListener(onChange);
return () => listController.removeListener(onChange);
}, [listController]);
return Container(
padding: .symmetric(horizontal: 16),
constraints: .loose(.new(500, 700)),
child: ref
.watch(EmojiController.provider)
.betterWhen(
data: (categories) {
final combined = categories.addAll(extraCategories);
return Column(
spacing: 4,
children: [
SearchAnchor.bar(
barHintText: "Search emoji",
suggestionsBuilder: (context, controller) {
return [];
return Column(
spacing: 4,
children: [
SearchAnchor.bar(
barHintText: "Search emoji",
suggestionsBuilder: (context, controller) {
return [];
},
),
SizedBox(
height: 48,
child: ListView(
scrollDirection: .horizontal,
children: combined
.mapIndexed(
(index, category) => Padding(
padding: .symmetric(horizontal: 4),
child: FilterChip(
label: Text(category.name),
avatar: category.icon,
selected: selectedCategory.value == index,
showCheckmark: false,
onSelected: (_) {
selectedCategory.value = index;
listController.animateToItem(
index: index,
scrollController: scrollController,
curve: (_) => Curves.easeInOut,
duration: (_) =>
Duration(milliseconds: 300),
alignment: 0,
);
},
),
),
)
.toList(),
),
),
Expanded(
child: SuperListView.builder(
listController: listController,
controller: scrollController,
itemCount: combined.length,
itemBuilder: (context, index) {
final category = combined[index];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DividerText(category.name),
Wrap(
children: category.emojis
.map(
(emoji) => IconButton(
onPressed: () {},
icon: SizedBox.square(
dimension: 36,
child: FittedBox(
fit: .contain,
child: emoji.widget,
),
),
),
)
.toList(),
),
],
);
},
),
SizedBox(
height: 48,
child: ListView(
scrollDirection: .horizontal,
children: combined
.mapIndexed(
(index, category) => Padding(
padding: .symmetric(horizontal: 4),
child: FilterChip(
label: Text(category.name),
avatar: category.icon,
selected: selectedCategory.value == index,
showCheckmark: false,
onSelected: (_) {
selectedCategory.value = index;
listController.animateToItem(
index: index,
scrollController: scrollController,
curve: (_) => Curves.easeInOut,
duration: (_) =>
Duration(milliseconds: 300),
alignment: 0,
);
},
),
),
)
.toList(),
),
),
Expanded(
child: SuperListView.builder(
listController: listController,
controller: scrollController,
itemCount: combined.length,
itemBuilder: (context, index) {
final category = combined[index];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DividerText(category.name),
DefaultTextStyle(
style: TextStyle(fontSize: 24),
child: GridView(
gridDelegate:
const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 52,
mainAxisExtent: 52,
),
children: category.emojis
.map(
(emoji) => IconButton(
onPressed: () {},
icon: emoji.widget,
),
)
.toList(),
),
),
],
);
},
),
),
],
);
},
);
},
),
);
),
],
);
},
),
);
}
}