From 08cf09ecc2f01188394a77fe6757955ed38f02a6 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Thu, 17 Sep 2026 11:16:41 -0400 Subject: [PATCH] replace for ... in with mapIndexed where possible --- lib/src/widgets/emoji_picker.dart | 178 +++++++++++++++--------------- 1 file changed, 92 insertions(+), 86 deletions(-) diff --git a/lib/src/widgets/emoji_picker.dart b/lib/src/widgets/emoji_picker.dart index eecdf95..bbf53fa 100644 --- a/lib/src/widgets/emoji_picker.dart +++ b/lib/src/widgets/emoji_picker.dart @@ -1,5 +1,6 @@ import "dart:async"; +import "package:collection/collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:flutter_hooks/flutter_hooks.dart"; import "package:hooks_riverpod/hooks_riverpod.dart"; @@ -126,32 +127,33 @@ class EmojiPicker extends HookConsumerWidget { padding: .only(bottom: 12), scrollDirection: .horizontal, controller: categoryScrollController, - children: [ - for (final (index, category) in combined.indexed) - Padding( - key: chipKeys[index], - padding: .symmetric(horizontal: 4), - child: FilterChip( - label: Text(category.name), - avatar: category.icon, - selected: selectedCategory.value == index, - showCheckmark: false, - onSelected: (_) { - selectedCategory.value = index; - final headerContext = - headerKeys[index].currentContext; - if (headerContext != null) { - Scrollable.ensureVisible( - headerContext, - duration: Duration(milliseconds: 300), - curve: Curves.easeInOut, - alignment: 0, - ); - } - }, + children: combined + .mapIndexed( + (index, category) => Padding( + key: chipKeys[index], + padding: .symmetric(horizontal: 4), + child: FilterChip( + label: Text(category.name), + avatar: category.icon, + selected: selectedCategory.value == index, + showCheckmark: false, + onSelected: (_) { + selectedCategory.value = index; + final headerContext = + headerKeys[index].currentContext; + if (headerContext != null) { + Scrollable.ensureVisible( + headerContext, + duration: Duration(milliseconds: 300), + curve: Curves.easeInOut, + alignment: 0, + ); + } + }, + ), ), - ), - ], + ) + .toList(), ), ), ), @@ -159,71 +161,75 @@ class EmojiPicker extends HookConsumerWidget { child: CustomScrollView( key: scrollViewKey, controller: scrollController, - slivers: [ - for (final (index, category) in combined.indexed) - Builder( - builder: (context) { - final headerKey = headerKeys[index]; - final emojis = search.value.isEmpty - ? category.emojis - : category.emojis - .where( - (emoji) => - emoji.aliases.join().contains( - search.value, - ) || - emoji.description.contains( - search.value, - ) || - emoji.tags.join().contains( - search.value, - ), - ) - .toIList(); + slivers: combined + .mapIndexed( + (index, category) => Builder( + builder: (context) { + final headerKey = headerKeys[index]; + final emojis = search.value.isEmpty + ? category.emojis + : category.emojis + .where( + (emoji) => + emoji.aliases.join().contains( + search.value, + ) || + emoji.description.contains( + search.value, + ) || + emoji.tags.join().contains( + search.value, + ), + ) + .toIList(); - if (emojis.isEmpty) { - return SliverToBoxAdapter( - child: SizedBox.shrink(key: headerKey), - ); - } + if (emojis.isEmpty) { + return SliverToBoxAdapter( + child: SizedBox.shrink(key: headerKey), + ); + } - return SliverMainAxisGroup( - slivers: [ - SliverToBoxAdapter( - child: Text( - key: headerKey, - category.name, - style: Theme.of(context) - .textTheme - .titleMedium, + return SliverMainAxisGroup( + slivers: [ + SliverToBoxAdapter( + child: Text( + key: headerKey, + category.name, + style: Theme.of(context) + .textTheme + .titleMedium, + ), ), - ), - SliverGrid.builder( - gridDelegate: - const SliverGridDelegateWithMaxCrossAxisExtent( - maxCrossAxisExtent: 56, - mainAxisExtent: 56, - ), - itemCount: emojis.length, - itemBuilder: (context, index) { - final emoji = emojis[index]; + SliverGrid.builder( + gridDelegate: + const SliverGridDelegateWithMaxCrossAxisExtent( + maxCrossAxisExtent: 56, + mainAxisExtent: 56, + ), + itemCount: emojis.length, + itemBuilder: (context, index) { + final emoji = emojis[index]; - return IconButton( - padding: EdgeInsets.zero, - onPressed: () => onSelection(emoji.value), - icon: SizedBox.square( - dimension: 36, - child: FittedBox(child: emoji.widget), - ), - ); - }, - ), - SliverToBoxAdapter(child: SizedBox(height: 4)), - ], - ); - }, - ), - ], + return IconButton( + padding: EdgeInsets.zero, + onPressed: () => + onSelection(emoji.value), + icon: SizedBox.square( + dimension: 36, + child: FittedBox(child: emoji.widget), + ), + ); + }, + ), + SliverToBoxAdapter( + child: SizedBox(height: 4), + ), + ], + ); + }, + ), + ) + .toList(), ), ), ],