mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
Album & Artist names are clickable now
Artist & Album text now navigates to the AlbumView/ArtistProfile pages
This commit is contained in:
parent
58148f3493
commit
73a11dc429
@ -8,7 +8,7 @@ import 'package:spotube/provider/Playback.dart';
|
||||
import 'package:spotube/provider/SpotifyDI.dart';
|
||||
|
||||
class AlbumView extends StatelessWidget {
|
||||
final Album album;
|
||||
final AlbumSimple album;
|
||||
const AlbumView(this.album, {Key? key}) : super(key: key);
|
||||
|
||||
playPlaylist(Playback playback, List<Track> tracks, {Track? currentTrack}) {
|
||||
|
@ -4,9 +4,12 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:hotkey_manager/hotkey_manager.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
import 'package:spotube/components/Artist/ArtistProfile.dart';
|
||||
import 'package:spotube/components/Shared/DownloadTrackButton.dart';
|
||||
import 'package:spotube/components/Player/PlayerControls.dart';
|
||||
import 'package:spotube/components/Shared/LinkText.dart';
|
||||
import 'package:spotube/helpers/artist-to-string.dart';
|
||||
import 'package:spotube/helpers/artists-to-clickable-artists.dart';
|
||||
import 'package:spotube/helpers/search-youtube.dart';
|
||||
import 'package:spotube/models/GlobalKeyActions.dart';
|
||||
import 'package:spotube/provider/Playback.dart';
|
||||
@ -240,8 +243,9 @@ class _PlayerState extends State<Player> with WidgetsBindingObserver {
|
||||
playback.currentTrack?.name ?? "Not playing",
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(artistsToString<Artist>(
|
||||
playback.currentTrack?.artists ?? []))
|
||||
artistsToClickableArtists(
|
||||
playback.currentTrack?.artists ?? [],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
50
lib/components/Shared/LinkText.dart
Normal file
50
lib/components/Shared/LinkText.dart
Normal file
@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LinkText<T> extends StatefulWidget {
|
||||
final String text;
|
||||
final TextStyle style;
|
||||
final TextAlign? textAign;
|
||||
final TextOverflow? overflow;
|
||||
final Route<T> route;
|
||||
|
||||
const LinkText(
|
||||
this.text,
|
||||
this.route, {
|
||||
Key? key,
|
||||
this.textAign,
|
||||
this.overflow,
|
||||
this.style = const TextStyle(),
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<LinkText<T>> createState() => _LinkTextState<T>();
|
||||
}
|
||||
|
||||
class _LinkTextState<T> extends State<LinkText<T>> {
|
||||
bool _hover = false;
|
||||
bool _tap = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
child: MouseRegion(
|
||||
cursor: MaterialStateMouseCursor.clickable,
|
||||
child: Text(
|
||||
widget.text,
|
||||
style: widget.style.copyWith(
|
||||
decoration: _hover || _tap ? TextDecoration.underline : null,
|
||||
),
|
||||
textAlign: widget.textAign,
|
||||
overflow: widget.overflow,
|
||||
),
|
||||
onEnter: (event) => setState(() => _hover = true),
|
||||
onExit: (event) => setState(() => _hover = false),
|
||||
),
|
||||
onTapDown: (event) => setState(() => _tap = true),
|
||||
onTapUp: (event) => setState(() => _tap = false),
|
||||
onTap: () {
|
||||
Navigator.of(context).push(widget.route);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -2,6 +2,10 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
import 'package:spotube/components/Album/AlbumView.dart';
|
||||
import 'package:spotube/components/Artist/ArtistProfile.dart';
|
||||
import 'package:spotube/components/Shared/LinkText.dart';
|
||||
import 'package:spotube/helpers/artists-to-clickable-artists.dart';
|
||||
import 'package:spotube/helpers/zero-pad-num-str.dart';
|
||||
import 'package:spotube/provider/Playback.dart';
|
||||
|
||||
@ -76,12 +80,7 @@ class TracksTableView extends StatelessWidget {
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
(track.value.artists ?? [])
|
||||
.map((e) => e.name)
|
||||
.join(", "),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
artistsToClickableArtists(track.value.artists ?? []),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -91,8 +90,11 @@ class TracksTableView extends StatelessWidget {
|
||||
TableCell(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
child: LinkText(
|
||||
track.value.album?.name ?? "",
|
||||
MaterialPageRoute(
|
||||
builder: (context) => AlbumView(track.value.album!),
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
|
24
lib/helpers/artists-to-clickable-artists.dart
Normal file
24
lib/helpers/artists-to-clickable-artists.dart
Normal file
@ -0,0 +1,24 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
import 'package:spotube/components/Artist/ArtistProfile.dart';
|
||||
import 'package:spotube/components/Shared/LinkText.dart';
|
||||
|
||||
Widget artistsToClickableArtists(List<ArtistSimple> artists) {
|
||||
return Row(
|
||||
children: artists
|
||||
.asMap()
|
||||
.entries
|
||||
.map(
|
||||
(artist) => LinkText(
|
||||
(artist.key != artists.length - 1)
|
||||
? "${artist.value.name}, "
|
||||
: artist.value.name!,
|
||||
MaterialPageRoute<ArtistProfile>(
|
||||
builder: (context) => ArtistProfile(artist.value.id!),
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import 'package:spotify/spotify.dart';
|
||||
|
||||
Track simpleTrackToTrack(TrackSimple trackSmp, Album album) {
|
||||
Track simpleTrackToTrack(TrackSimple trackSmp, AlbumSimple album) {
|
||||
Track track = Track();
|
||||
track.name = trackSmp.name;
|
||||
track.album = album;
|
||||
|
Loading…
Reference in New Issue
Block a user