diff --git a/lib/widgets/emoji_picker.dart b/lib/widgets/emoji_picker.dart index 7b8933c..079eae5 100644 --- a/lib/widgets/emoji_picker.dart +++ b/lib/widgets/emoji_picker.dart @@ -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(null); + final scrollController = useScrollController(); + final listController = useMemoized(ListController.new); - return HookBuilder( - builder: (context) { - final selectedCategory = useState(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(), - ), - ), - ], - ); - }, - ), - ), - ], - ); - }, - ); - }, - ), - ); + ), + ], + ); + }, + ), + ); + } }