Skip to content

Commit

Permalink
refactor: genre home section
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jan 5, 2025
1 parent dff8fe2 commit e6408cc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 80 deletions.
4 changes: 2 additions & 2 deletions lib/components/fallbacks/anonymous_fallback.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
import 'package:spotube/extensions/context.dart';
import 'package:spotube/pages/settings/settings.dart';

Expand Down Expand Up @@ -28,7 +28,7 @@ class AnonymousFallback extends ConsumerWidget {
children: [
Text(context.l10n.not_logged_in),
const SizedBox(height: 10),
FilledButton(
Button.primary(
child: Text(context.l10n.login_with_spotify),
onPressed: () => ServiceUtils.pushNamed(context, SettingsPage.name),
)
Expand Down
8 changes: 3 additions & 5 deletions lib/components/fallbacks/not_found.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
import 'package:spotube/collections/assets.gen.dart';
import 'package:spotube/extensions/context.dart';

Expand All @@ -8,7 +8,6 @@ class NotFound extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final widgets = [
SizedBox(
height: 150,
Expand All @@ -19,11 +18,10 @@ class NotFound extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(context.l10n.nothing_found, style: theme.textTheme.titleLarge),
Text(context.l10n.nothing_found).large().semiBold(),
Text(
context.l10n.the_box_is_empty,
style: theme.textTheme.titleMedium,
),
).semiBold(),
],
),
];
Expand Down
88 changes: 24 additions & 64 deletions lib/modules/home/sections/genres.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:math';

import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
Expand All @@ -8,7 +6,6 @@ import 'package:shadcn_flutter/shadcn_flutter_extension.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/image/universal_image.dart';
import 'package:spotube/extensions/constrains.dart';
Expand Down Expand Up @@ -84,70 +81,33 @@ class HomeGenresSection extends HookConsumerWidget {
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.gray[900]
: Colors.white;
return (
gradient: LinearGradient(
colors: gradient.colors
.map((c) => c.withAlpha((0.8 * 255).ceil()))
.toList(),
),
textColor: text
return Button(
style: ButtonVariance.secondary.copyWith(
padding: (context, states, value) {
return EdgeInsets.zero;
},
),
onPressed: () {},
child: CardImage(
onPressed: () {
context.pushNamed(
GenrePlaylistsPage.name,
pathParameters: {
"categoryId": category.id!,
},
extra: category,
);
},
[],
);

return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
context.pushNamed(
GenrePlaylistsPage.name,
pathParameters: {
"categoryId": category.id!,
},
extra: category,
);
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
image: DecorationImage(
image: UniversalImage.imageProvider(
category.icons!.first.url!,
),
fit: BoxFit.cover,
),
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: context.theme.colorScheme.muted,
gradient:
categoriesQuery.isLoading ? null : gradient,
),
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
category.name!,
style: context.theme.typography.large,
),
),
),
),
direction: Axis.horizontal,
image: UniversalImage(
path: category.icons!.first.url!,
fit: BoxFit.cover,
height: 50,
width: 50,
),
);
});
title: Text(category.name!),
),
);
},
),
),
Expand Down
19 changes: 10 additions & 9 deletions lib/pages/lastfm_login/lastfm_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ class LastFMLoginPage extends HookConsumerWidget {
),
),
],
child: SingleChildScrollView(
child: Container(
constraints: const BoxConstraints(maxWidth: 400),
alignment: Alignment.center,
padding: const EdgeInsets.all(16),
child: Card(
child: Padding(
padding: const EdgeInsets.all(16.0).copyWith(top: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
constraints: const BoxConstraints(maxWidth: 400),
alignment: Alignment.center,
padding: const EdgeInsets.all(16),
child: Card(
padding: const EdgeInsets.all(16.0),
child: Form(
onSubmit: (context, values) async {
try {
Expand Down Expand Up @@ -136,7 +137,7 @@ class LastFMLoginPage extends HookConsumerWidget {
),
),
),
),
],
),
);
}
Expand Down

0 comments on commit e6408cc

Please sign in to comment.