replace for ... in with mapIndexed where possible
This commit is contained in:
parent
67a31eb1fd
commit
08cf09ecc2
1 changed files with 95 additions and 89 deletions
|
|
@ -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(),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue