✨ Playlist & tracks
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get_navigation/src/root/get_material_app.dart';
|
||||
import 'package:rhythm_box/providers/spotify.dart';
|
||||
import 'package:rhythm_box/router.dart';
|
||||
import 'package:rhythm_box/translations.dart';
|
||||
|
||||
@@ -40,5 +40,7 @@ class MyApp extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _initializeProviders(BuildContext context) async {}
|
||||
void _initializeProviders(BuildContext context) async {
|
||||
Get.lazyPut(() => SpotifyProvider());
|
||||
}
|
||||
}
|
||||
|
41
lib/platform.dart
Normal file
41
lib/platform.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
abstract class PlatformInfo {
|
||||
static bool get isWeb => kIsWeb;
|
||||
|
||||
static bool get isLinux => !kIsWeb && Platform.isLinux;
|
||||
|
||||
static bool get isWindows => !kIsWeb && Platform.isWindows;
|
||||
|
||||
static bool get isMacOS => !kIsWeb && Platform.isMacOS;
|
||||
|
||||
static bool get isIOS => !kIsWeb && Platform.isIOS;
|
||||
|
||||
static bool get isAndroid => !kIsWeb && Platform.isAndroid;
|
||||
|
||||
static bool get isMobile => isAndroid || isIOS;
|
||||
|
||||
// Not first tier supported platform
|
||||
static bool get isBetaDesktop => isWindows || isLinux;
|
||||
|
||||
static bool get isDesktop => isLinux || isWindows || isMacOS;
|
||||
|
||||
static bool get useTouchscreen => !isMobile;
|
||||
|
||||
static bool get canCacheImage => isAndroid || isIOS || isMacOS;
|
||||
|
||||
static bool get canRecord => (isMobile || isMacOS);
|
||||
|
||||
static bool get canPushNotification => isAndroid || isIOS || isMacOS;
|
||||
|
||||
static Future<String> getVersion() async {
|
||||
var version = kIsWeb ? 'Web' : 'Unknown';
|
||||
try {
|
||||
version = (await PackageInfo.fromPlatform()).version;
|
||||
} catch (_) {}
|
||||
return version;
|
||||
}
|
||||
}
|
17
lib/providers/spotify.dart
Normal file
17
lib/providers/spotify.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
|
||||
class SpotifyProvider extends GetxController {
|
||||
late final SpotifyApi api;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
api = SpotifyApi(
|
||||
SpotifyApiCredentials(
|
||||
"f73d4bff91d64d89be9930036f553534",
|
||||
"5cbec0b928d247cd891d06195f07b8c9",
|
||||
),
|
||||
);
|
||||
super.onInit();
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:rhythm_box/screens/explore.dart';
|
||||
import 'package:rhythm_box/screens/playlist/view.dart';
|
||||
import 'package:rhythm_box/screens/settings.dart';
|
||||
import 'package:rhythm_box/shells/nav_shell.dart';
|
||||
|
||||
@@ -12,6 +13,13 @@ final router = GoRouter(routes: [
|
||||
name: "explore",
|
||||
builder: (context, state) => const ExploreScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: "/playlist/:id",
|
||||
name: "playlistView",
|
||||
builder: (context, state) => PlaylistViewScreen(
|
||||
playlistId: state.pathParameters['id']!,
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: "/settings",
|
||||
name: "settings",
|
||||
|
@@ -1,4 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:rhythm_box/providers/spotify.dart';
|
||||
import 'package:rhythm_box/widgets/auto_cache_image.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
|
||||
class ExploreScreen extends StatefulWidget {
|
||||
const ExploreScreen({super.key});
|
||||
@@ -8,8 +14,73 @@ class ExploreScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ExploreScreenState extends State<ExploreScreen> {
|
||||
late final SpotifyProvider _spotify = Get.find();
|
||||
|
||||
bool _isLoading = true;
|
||||
|
||||
List<PlaylistSimple>? _featuredPlaylist;
|
||||
|
||||
Future<void> _pullPlaylist() async {
|
||||
_featuredPlaylist =
|
||||
(await _spotify.api.playlists.featured.all(10)).toList();
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_pullPlaylist();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
return Material(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('explore'.tr),
|
||||
),
|
||||
body: Skeletonizer(
|
||||
enabled: _isLoading,
|
||||
child: ListView.builder(
|
||||
itemCount: _featuredPlaylist?.length ?? 20,
|
||||
itemBuilder: (context, idx) {
|
||||
final item = _featuredPlaylist?[idx];
|
||||
return ListTile(
|
||||
leading: ClipRRect(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(16)),
|
||||
child: item != null
|
||||
? AutoCacheImage(
|
||||
item.images!.first.url!,
|
||||
width: 64.0,
|
||||
height: 64.0,
|
||||
)
|
||||
: const SizedBox(
|
||||
width: 64,
|
||||
height: 64,
|
||||
child: Center(
|
||||
child: Icon(Icons.image),
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(item?.name ?? 'Loading...'),
|
||||
subtitle: Text(
|
||||
item?.description ?? 'Please stand by...',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
onTap: () {
|
||||
if (item == null) return;
|
||||
GoRouter.of(context).pushNamed(
|
||||
'playlistView',
|
||||
pathParameters: {'id': item.id!},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
149
lib/screens/playlist/view.dart
Normal file
149
lib/screens/playlist/view.dart
Normal file
@@ -0,0 +1,149 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:rhythm_box/providers/spotify.dart';
|
||||
import 'package:rhythm_box/widgets/auto_cache_image.dart';
|
||||
import 'package:rhythm_box/widgets/tracks/playlist_track_list.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
|
||||
class PlaylistViewScreen extends StatefulWidget {
|
||||
final String playlistId;
|
||||
final Playlist? playlist;
|
||||
|
||||
const PlaylistViewScreen({
|
||||
super.key,
|
||||
required this.playlistId,
|
||||
this.playlist,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PlaylistViewScreen> createState() => _PlaylistViewScreenState();
|
||||
}
|
||||
|
||||
class _PlaylistViewScreenState extends State<PlaylistViewScreen> {
|
||||
late final SpotifyProvider _spotify = Get.find();
|
||||
|
||||
bool _isLoading = true;
|
||||
|
||||
Playlist? _playlist;
|
||||
|
||||
Future<void> _pullPlaylist() async {
|
||||
_playlist = await _spotify.api.playlists.get(widget.playlistId);
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_pullPlaylist();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const radius = BorderRadius.all(Radius.circular(8));
|
||||
|
||||
return Material(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Playlist'),
|
||||
),
|
||||
body: Builder(
|
||||
builder: (context) {
|
||||
if (_isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Material(
|
||||
borderRadius: radius,
|
||||
elevation: 2,
|
||||
child: ClipRRect(
|
||||
borderRadius: radius,
|
||||
child: Hero(
|
||||
tag: Key('playlist-cover-${_playlist!.id}'),
|
||||
child: AutoCacheImage(
|
||||
_playlist!.images!.first.url!,
|
||||
width: 160.0,
|
||||
height: 160.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Gap(24),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_playlist!.name ?? 'Playlist',
|
||||
style:
|
||||
Theme.of(context).textTheme.headlineSmall,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.fade,
|
||||
),
|
||||
Text(
|
||||
_playlist!.description ?? 'A Playlist',
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const Gap(8),
|
||||
Text(
|
||||
"${NumberFormat.compactCurrency(symbol: '', decimalDigits: 2).format(_playlist!.followers!.total!)} saves",
|
||||
),
|
||||
Text(
|
||||
"#${_playlist!.id}",
|
||||
style: GoogleFonts.robotoMono(fontSize: 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
).paddingOnly(left: 24, right: 24, top: 24),
|
||||
const Gap(8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
ElevatedButton.icon(
|
||||
icon: const Icon(Icons.play_arrow_outlined),
|
||||
label: const Text('Play'),
|
||||
onPressed: () {},
|
||||
),
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.shuffle),
|
||||
label: const Text('Shuffle'),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
).paddingSymmetric(horizontal: 24),
|
||||
const Gap(24),
|
||||
],
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Text(
|
||||
'Songs (${_playlist!.tracks!.total})',
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
).paddingOnly(left: 28, right: 28, bottom: 4),
|
||||
),
|
||||
PlaylistTrackList(playlistId: widget.playlistId),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
26
lib/widgets/auto_cache_image.dart
Normal file
26
lib/widgets/auto_cache_image.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rhythm_box/platform.dart';
|
||||
|
||||
class AutoCacheImage extends StatelessWidget {
|
||||
final String url;
|
||||
final double? width, height;
|
||||
|
||||
const AutoCacheImage(this.url, {super.key, this.width, this.height});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (PlatformInfo.canCacheImage) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: url,
|
||||
width: width,
|
||||
height: height,
|
||||
);
|
||||
}
|
||||
return Image.network(
|
||||
url,
|
||||
width: width,
|
||||
height: height,
|
||||
);
|
||||
}
|
||||
}
|
73
lib/widgets/tracks/playlist_track_list.dart
Normal file
73
lib/widgets/tracks/playlist_track_list.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rhythm_box/providers/spotify.dart';
|
||||
import 'package:rhythm_box/widgets/auto_cache_image.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
|
||||
class PlaylistTrackList extends StatefulWidget {
|
||||
final String playlistId;
|
||||
|
||||
const PlaylistTrackList({super.key, required this.playlistId});
|
||||
|
||||
@override
|
||||
State<PlaylistTrackList> createState() => _PlaylistTrackListState();
|
||||
}
|
||||
|
||||
class _PlaylistTrackListState extends State<PlaylistTrackList> {
|
||||
late final SpotifyProvider _spotify = Get.find();
|
||||
|
||||
bool _isLoading = true;
|
||||
|
||||
List<Track>? _tracks;
|
||||
|
||||
Future<void> _pullTracks() async {
|
||||
_tracks = (await _spotify.api.playlists
|
||||
.getTracksByPlaylistId(widget.playlistId)
|
||||
.all())
|
||||
.toList();
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_pullTracks();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Skeletonizer.sliver(
|
||||
enabled: _isLoading,
|
||||
child: SliverList.builder(
|
||||
itemCount: _tracks?.length ?? 3,
|
||||
itemBuilder: (context, idx) {
|
||||
final item = _tracks?[idx];
|
||||
return ListTile(
|
||||
leading: ClipRRect(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(16)),
|
||||
child: item != null
|
||||
? AutoCacheImage(
|
||||
item.album!.images!.first.url!,
|
||||
width: 64.0,
|
||||
height: 64.0,
|
||||
)
|
||||
: const SizedBox(
|
||||
width: 64,
|
||||
height: 64,
|
||||
child: Center(
|
||||
child: Icon(Icons.image),
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(item?.name ?? 'Loading...'),
|
||||
subtitle: Text(
|
||||
item?.artists!.map((x) => x.name!).join(', ') ??
|
||||
'Please stand by...',
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user