Skip to content

Commit

Permalink
chore: fix alternative source list item theme inconsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jan 5, 2025
1 parent b734985 commit dff8fe2
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 80 deletions.
24 changes: 16 additions & 8 deletions lib/components/ui/button_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ButtonTile extends StatelessWidget {
final void Function()? onPressed;
final bool selected;
final ButtonVariance style;
final EdgeInsets? padding;

const ButtonTile({
super.key,
Expand All @@ -19,6 +20,7 @@ class ButtonTile extends StatelessWidget {
this.enabled = true,
this.onPressed,
this.selected = false,
this.padding,
this.style = ButtonVariance.outline,
});

Expand All @@ -30,17 +32,23 @@ class ButtonTile extends StatelessWidget {
enabled: enabled,
onPressed: onPressed,
style: style.copyWith(
padding: padding != null ? (context, states, value) => padding! : null,
decoration: (context, states, value) {
final decoration = style.decoration(context, states) as BoxDecoration;

if (selected && style == ButtonVariance.outline) {
return decoration.copyWith(
border: Border.all(
color: colorScheme.primary,
width: 1.0,
),
color: colorScheme.primary.withAlpha(25),
);
if (selected) {
return switch (style) {
ButtonVariance.outline => decoration.copyWith(
border: Border.all(
color: colorScheme.primary,
width: 1.0,
),
color: colorScheme.primary.withAlpha(25),
),
ButtonVariance.ghost || _ => decoration.copyWith(
color: colorScheme.primary.withAlpha(25),
),
};
}

return decoration;
Expand Down
135 changes: 63 additions & 72 deletions lib/modules/player/sibling_tracks_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart' show ListTile, Material, MaterialType;

import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
import 'package:shadcn_flutter/shadcn_flutter_extension.dart';
import 'package:spotube/collections/assets.gen.dart';
import 'package:spotube/collections/spotube_icons.dart';

import 'package:spotube/components/image/universal_image.dart';
import 'package:spotube/components/inter_scrollbar/inter_scrollbar.dart';
import 'package:spotube/components/ui/button_tile.dart';
import 'package:spotube/extensions/artist_simple.dart';
import 'package:spotube/extensions/context.dart';
import 'package:spotube/extensions/duration.dart';
Expand All @@ -18,7 +18,6 @@ import 'package:spotube/provider/audio_player/audio_player.dart';
import 'package:spotube/provider/audio_player/querying_track_info.dart';
import 'package:spotube/provider/server/active_sourced_track.dart';
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';

import 'package:spotube/services/sourced_track/models/source_info.dart';
import 'package:spotube/services/sourced_track/models/video_info.dart';
import 'package:spotube/services/sourced_track/sourced_track.dart';
Expand Down Expand Up @@ -161,40 +160,36 @@ class SiblingTracksSheet extends HookConsumerWidget {
final itemBuilder = useCallback(
(SourceInfo sourceInfo) {
final icon = sourceInfoToIconMap[sourceInfo.runtimeType];
return ListTile(
hoverColor: theme.colorScheme.primary.withOpacity(.1),
dense: true,
subtitleTextStyle: theme.typography.small.copyWith(
color: theme.colorScheme.mutedForeground,
),
titleTextStyle: theme.typography.normal,
leadingAndTrailingTextStyle: theme.typography.normal,
title: Text(sourceInfo.title),
horizontalTitleGap: 0,
leading: Padding(
padding: const EdgeInsets.only(top: 8.0, right: 8.0),
child: UniversalImage(
path: sourceInfo.thumbnail,
height: 60,
width: 60,
),
return ButtonTile(
style: ButtonVariance.ghost,
padding: const EdgeInsets.symmetric(horizontal: 8),
title: Text(
sourceInfo.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
leading: UniversalImage(
path: sourceInfo.thumbnail,
height: 60,
width: 60,
),
trailing: Text(sourceInfo.duration.toHumanReadableString()),
subtitle: Row(
children: [
if (icon != null) icon,
Text(" • ${sourceInfo.artist}"),
Flexible(
child: Text(
" • ${sourceInfo.artist}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
enabled: !isFetchingActiveTrack,
selected: !isFetchingActiveTrack &&
sourceInfo.id == (activeTrack as SourcedTrack).sourceInfo.id,
selectedTileColor: theme.colorScheme.primary.withOpacity(.1),
selectedColor: theme.colorScheme.primary,
onTap: () {
onPressed: () {
if (!isFetchingActiveTrack &&
sourceInfo.id != (activeTrack as SourcedTrack).sourceInfo.id) {
activeTrackNotifier.swapSibling(sourceInfo);
Expand Down Expand Up @@ -222,20 +217,17 @@ class SiblingTracksSheet extends HookConsumerWidget {
child: !isSearching.value
? Text(
context.l10n.alternative_track_sources,
style: theme.typography.bold,
)
: Flexible(
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: 320 * scale,
maxHeight: 38 * scale,
),
child: TextField(
autofocus: true,
controller: searchController,
placeholder: Text(context.l10n.search),
style: theme.typography.bold,
),
).bold()
: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: 320 * scale,
maxHeight: 38 * scale,
),
child: TextField(
autofocus: true,
controller: searchController,
placeholder: Text(context.l10n.search),
style: theme.typography.bold,
),
),
),
Expand Down Expand Up @@ -290,39 +282,38 @@ class SiblingTracksSheet extends HookConsumerWidget {
FadeTransition(opacity: animation, child: child),
child: InterScrollbar(
controller: controller,
child: Material(
type: MaterialType.transparency,
child: switch (isSearching.value) {
false => ListView.builder(
padding: const EdgeInsets.all(8.0),
controller: controller,
itemCount: siblings.length,
itemBuilder: (context, index) =>
itemBuilder(siblings[index]),
),
true => FutureBuilder(
future: searchRequest,
builder: (context, snapshot) {
if (snapshot.hasError) {
return Center(
child: Text(snapshot.error.toString()),
);
} else if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator());
}

return ListView.builder(
padding: const EdgeInsets.all(8.0),
controller: controller,
itemCount: snapshot.data!.length,
itemBuilder: (context, index) =>
itemBuilder(snapshot.data![index]),
child: switch (isSearching.value) {
false => ListView.separated(
padding: const EdgeInsets.all(8.0),
controller: controller,
itemCount: siblings.length,
separatorBuilder: (context, index) => const Gap(8),
itemBuilder: (context, index) =>
itemBuilder(siblings[index]),
),
true => FutureBuilder(
future: searchRequest,
builder: (context, snapshot) {
if (snapshot.hasError) {
return Center(
child: Text(snapshot.error.toString()),
);
},
),
},
),
} else if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator());
}

return ListView.separated(
padding: const EdgeInsets.all(8.0),
controller: controller,
itemCount: snapshot.data!.length,
separatorBuilder: (context, index) => const Gap(8),
itemBuilder: (context, index) =>
itemBuilder(snapshot.data![index]),
);
},
),
},
),
),
),
Expand Down

0 comments on commit dff8fe2

Please sign in to comment.