mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00

* feat: add riverpod based favorite album provider * feat: add album is saved, new releases and tracks providers * feat: add artist related providers * feat: add all categories providers * feat: add lyrics provider * feat: add playlist related providers * feat: add search provider * feat: add view and spotify friends provider * feat: add playlist create and update and favorite handlers * feat: use providers in home screen * chore: fix dart lint issues * feat: use new providers for playlist and albums screen * feat: use providers in artist page * feat: use providers on library page * feat: use provider for playlist and album card and heart button * feat: use provider in search page * feat: use providers in generate playlist * feat: use provider in lyrics screen * feat: use provider for create playlist * feat: use provider in add track dialog * feat: use providers in remaining pages and remove fl_query * fix: remove direct access to provider.value * fix: glitching when loading * fix: user album loading next page indicator * feat: make many provider autoDispose after 5 minutes of no usage * fix: ignore episodes in tracks
153 lines
5.6 KiB
Dart
153 lines
5.6 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
import 'package:gap/gap.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:skeletonizer/skeletonizer.dart';
|
|
import 'package:spotify/spotify.dart';
|
|
import 'package:spotube/collections/fake.dart';
|
|
import 'package:spotube/collections/gradients.dart';
|
|
import 'package:spotube/collections/spotube_icons.dart';
|
|
import 'package:spotube/components/shared/image/universal_image.dart';
|
|
import 'package:spotube/extensions/constrains.dart';
|
|
import 'package:spotube/extensions/context.dart';
|
|
import 'package:spotube/provider/spotify/spotify.dart';
|
|
|
|
class HomeGenresSection extends HookConsumerWidget {
|
|
const HomeGenresSection({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, ref) {
|
|
final ThemeData(:textTheme, :colorScheme) = Theme.of(context);
|
|
final mediaQuery = MediaQuery.of(context);
|
|
|
|
final categoriesQuery = ref.watch(categoriesProvider);
|
|
final categories = useMemoized(
|
|
() =>
|
|
categoriesQuery.value
|
|
?.where((c) => (c.icons?.length ?? 0) > 0)
|
|
.take(mediaQuery.mdAndDown ? 6 : 10)
|
|
.toList() ??
|
|
<Category>[],
|
|
[mediaQuery.mdAndDown, categoriesQuery.value],
|
|
);
|
|
|
|
return SliverMainAxisGroup(
|
|
slivers: [
|
|
SliverToBoxAdapter(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
context.l10n.genres,
|
|
style: textTheme.headlineSmall,
|
|
),
|
|
Directionality(
|
|
textDirection: TextDirection.rtl,
|
|
child: TextButton.icon(
|
|
onPressed: () {
|
|
context.push('/genres');
|
|
},
|
|
icon: const Icon(SpotubeIcons.angleRight),
|
|
label: Text(
|
|
"Browse All",
|
|
style: textTheme.bodyMedium?.copyWith(
|
|
color: colorScheme.secondary,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SliverGap(8),
|
|
SliverPadding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
sliver: Skeletonizer.sliver(
|
|
enabled: categoriesQuery.isLoading,
|
|
child: SliverGrid.builder(
|
|
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
|
maxCrossAxisExtent: mediaQuery.mdAndDown ? 200 : 250,
|
|
mainAxisExtent: 50,
|
|
crossAxisSpacing: 16,
|
|
mainAxisSpacing: 16,
|
|
),
|
|
itemCount: categoriesQuery.isLoading
|
|
? mediaQuery.mdAndDown
|
|
? 6
|
|
: 10
|
|
: categories.length,
|
|
itemBuilder: (context, index) {
|
|
final category =
|
|
categories.elementAtOrNull(index) ?? FakeData.category;
|
|
|
|
return HookBuilder(builder: (context) {
|
|
final (:gradient, :textColor) = useMemoized(
|
|
() {
|
|
final gradient =
|
|
gradients[Random().nextInt(gradients.length)];
|
|
final text = gradient.colors
|
|
.take(2)
|
|
.any((c) => c.computeLuminance() > 0.5)
|
|
? Colors.grey[900]
|
|
: Colors.white;
|
|
return (
|
|
gradient: LinearGradient(
|
|
colors: gradient.colors
|
|
.map((c) => c.withOpacity(0.8))
|
|
.toList(),
|
|
),
|
|
textColor: text
|
|
);
|
|
},
|
|
[],
|
|
);
|
|
|
|
return InkWell(
|
|
onTap: () {
|
|
context.push('/genre/${category.id}', extra: category);
|
|
},
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: Ink(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(8),
|
|
image: DecorationImage(
|
|
image: UniversalImage.imageProvider(
|
|
category.icons!.first.url!,
|
|
),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
child: Ink(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(5),
|
|
color: colorScheme.surfaceVariant,
|
|
gradient: categoriesQuery.isLoading ? null : gradient,
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
category.name!,
|
|
style: textTheme.titleMedium
|
|
?.copyWith(color: textColor),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|