chore: improve carousel performance

This commit is contained in:
Kingkor Roy Tirtho 2025-01-06 21:44:06 +06:00
parent 46852545a9
commit 3ffcb48db9

View File

@ -31,12 +31,12 @@ class HomeGenresSection extends HookConsumerWidget {
() =>
categoriesQuery.asData?.value
.where((c) => (c.icons?.length ?? 0) > 0)
.take(mediaQuery.mdAndDown ? 6 : 10)
.take(6)
.toList() ??
[
FakeData.category,
],
[mediaQuery.mdAndDown, categoriesQuery.asData?.value],
[categoriesQuery.asData?.value],
);
final controller = useMemoized(() => CarouselController(), []);
final interactedRef = useRef(false);
@ -159,14 +159,16 @@ class HomeGenresSection extends HookConsumerWidget {
child: Skeleton.ignore(
child: Skeletonizer(
enabled: playlists.isLoading,
child: SingleChildScrollView(
child: ListView.separated(
scrollDirection: Axis.horizontal,
child: Row(
spacing: 12,
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (final playlist in playlistsData)
Container(
itemCount: playlistsData.length,
separatorBuilder: (context, index) =>
const Gap(12),
itemBuilder: (context, index) {
final playlist =
playlistsData.elementAt(index);
return Container(
width: 115 * theme.scaling,
decoration: BoxDecoration(
color: theme.colorScheme.background
@ -177,17 +179,14 @@ class HomeGenresSection extends HookConsumerWidget {
borderRadius: theme.borderRadiusMd,
surfaceBlur: theme.surfaceBlur,
child: Button(
style: ButtonVariance.secondary
.copyWith(
padding:
(context, states, value) =>
style:
ButtonVariance.secondary.copyWith(
padding: (context, states, value) =>
const EdgeInsets.all(8),
decoration:
(context, states, value) {
final decoration =
ButtonVariance.secondary
.decoration(
context, states)
decoration: (context, states, value) {
final decoration = ButtonVariance
.secondary
.decoration(context, states)
as BoxDecoration;
if (states.isNotEmpty) {
@ -220,8 +219,7 @@ class HomeGenresSection extends HookConsumerWidget {
child: UniversalImage(
path: (playlist.images)!
.asUrlString(
placeholder:
ImagePlaceholder
placeholder: ImagePlaceholder
.collection,
index: 1,
),
@ -233,27 +231,23 @@ class HomeGenresSection extends HookConsumerWidget {
Text(
playlist.name!,
maxLines: 2,
overflow:
TextOverflow.ellipsis,
overflow: TextOverflow.ellipsis,
).semiBold().small(),
if (playlist.description !=
null)
if (playlist.description != null)
Text(
playlist.description
?.unescapeHtml()
.cleanHtml() ??
"",
maxLines: 2,
overflow:
TextOverflow.ellipsis,
overflow: TextOverflow.ellipsis,
).xSmall().muted(),
],
),
),
),
),
],
),
);
},
),
),
),