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 "dart:async";
|
||||||
|
|
||||||
|
import "package:collection/collection.dart";
|
||||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||||
import "package:flutter_hooks/flutter_hooks.dart";
|
import "package:flutter_hooks/flutter_hooks.dart";
|
||||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||||
|
|
@ -126,32 +127,33 @@ class EmojiPicker extends HookConsumerWidget {
|
||||||
padding: .only(bottom: 12),
|
padding: .only(bottom: 12),
|
||||||
scrollDirection: .horizontal,
|
scrollDirection: .horizontal,
|
||||||
controller: categoryScrollController,
|
controller: categoryScrollController,
|
||||||
children: [
|
children: combined
|
||||||
for (final (index, category) in combined.indexed)
|
.mapIndexed(
|
||||||
Padding(
|
(index, category) => Padding(
|
||||||
key: chipKeys[index],
|
key: chipKeys[index],
|
||||||
padding: .symmetric(horizontal: 4),
|
padding: .symmetric(horizontal: 4),
|
||||||
child: FilterChip(
|
child: FilterChip(
|
||||||
label: Text(category.name),
|
label: Text(category.name),
|
||||||
avatar: category.icon,
|
avatar: category.icon,
|
||||||
selected: selectedCategory.value == index,
|
selected: selectedCategory.value == index,
|
||||||
showCheckmark: false,
|
showCheckmark: false,
|
||||||
onSelected: (_) {
|
onSelected: (_) {
|
||||||
selectedCategory.value = index;
|
selectedCategory.value = index;
|
||||||
final headerContext =
|
final headerContext =
|
||||||
headerKeys[index].currentContext;
|
headerKeys[index].currentContext;
|
||||||
if (headerContext != null) {
|
if (headerContext != null) {
|
||||||
Scrollable.ensureVisible(
|
Scrollable.ensureVisible(
|
||||||
headerContext,
|
headerContext,
|
||||||
duration: Duration(milliseconds: 300),
|
duration: Duration(milliseconds: 300),
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
alignment: 0,
|
alignment: 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
],
|
.toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -159,71 +161,75 @@ class EmojiPicker extends HookConsumerWidget {
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
key: scrollViewKey,
|
key: scrollViewKey,
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
slivers: [
|
slivers: combined
|
||||||
for (final (index, category) in combined.indexed)
|
.mapIndexed(
|
||||||
Builder(
|
(index, category) => Builder(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
final headerKey = headerKeys[index];
|
final headerKey = headerKeys[index];
|
||||||
final emojis = search.value.isEmpty
|
final emojis = search.value.isEmpty
|
||||||
? category.emojis
|
? category.emojis
|
||||||
: category.emojis
|
: category.emojis
|
||||||
.where(
|
.where(
|
||||||
(emoji) =>
|
(emoji) =>
|
||||||
emoji.aliases.join().contains(
|
emoji.aliases.join().contains(
|
||||||
search.value,
|
search.value,
|
||||||
) ||
|
) ||
|
||||||
emoji.description.contains(
|
emoji.description.contains(
|
||||||
search.value,
|
search.value,
|
||||||
) ||
|
) ||
|
||||||
emoji.tags.join().contains(
|
emoji.tags.join().contains(
|
||||||
search.value,
|
search.value,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toIList();
|
.toIList();
|
||||||
|
|
||||||
if (emojis.isEmpty) {
|
if (emojis.isEmpty) {
|
||||||
return SliverToBoxAdapter(
|
return SliverToBoxAdapter(
|
||||||
child: SizedBox.shrink(key: headerKey),
|
child: SizedBox.shrink(key: headerKey),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SliverMainAxisGroup(
|
return SliverMainAxisGroup(
|
||||||
slivers: [
|
slivers: [
|
||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: Text(
|
child: Text(
|
||||||
key: headerKey,
|
key: headerKey,
|
||||||
category.name,
|
category.name,
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.titleMedium,
|
.titleMedium,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
SliverGrid.builder(
|
||||||
SliverGrid.builder(
|
gridDelegate:
|
||||||
gridDelegate:
|
const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||||
const SliverGridDelegateWithMaxCrossAxisExtent(
|
maxCrossAxisExtent: 56,
|
||||||
maxCrossAxisExtent: 56,
|
mainAxisExtent: 56,
|
||||||
mainAxisExtent: 56,
|
),
|
||||||
),
|
itemCount: emojis.length,
|
||||||
itemCount: emojis.length,
|
itemBuilder: (context, index) {
|
||||||
itemBuilder: (context, index) {
|
final emoji = emojis[index];
|
||||||
final emoji = emojis[index];
|
|
||||||
|
|
||||||
return IconButton(
|
return IconButton(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
onPressed: () => onSelection(emoji.value),
|
onPressed: () =>
|
||||||
icon: SizedBox.square(
|
onSelection(emoji.value),
|
||||||
dimension: 36,
|
icon: SizedBox.square(
|
||||||
child: FittedBox(child: emoji.widget),
|
dimension: 36,
|
||||||
),
|
child: FittedBox(child: emoji.widget),
|
||||||
);
|
),
|
||||||
},
|
);
|
||||||
),
|
},
|
||||||
SliverToBoxAdapter(child: SizedBox(height: 4)),
|
),
|
||||||
],
|
SliverToBoxAdapter(
|
||||||
);
|
child: SizedBox(height: 4),
|
||||||
},
|
),
|
||||||
),
|
],
|
||||||
],
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue