spotify integration works
This commit is contained in:
parent
f70fe3cdd1
commit
025eee7644
11 changed files with 1637 additions and 717 deletions
|
@ -1,271 +1,201 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../services/music_queue_service.dart';
|
||||
import '../models/spotify_track.dart';
|
||||
|
||||
class NowPlayingPage extends StatefulWidget {
|
||||
class NowPlayingPage extends StatelessWidget {
|
||||
const NowPlayingPage({super.key});
|
||||
|
||||
@override
|
||||
State<NowPlayingPage> createState() => _NowPlayingPageState();
|
||||
}
|
||||
|
||||
class _NowPlayingPageState extends State<NowPlayingPage> {
|
||||
// Mock data for demonstration
|
||||
bool isPlaying = false;
|
||||
String currentSong = "Summer Vibes";
|
||||
String currentArtist = "Chill Collective";
|
||||
double progress = 0.3; // 30% through song
|
||||
|
||||
List<Map<String, String>> upcomingQueue = [
|
||||
{"title": "Ocean Breeze", "artist": "Lofi Dreams", "votes": "12", "position": "1", "imageUrl": "https://i.scdn.co/image/ocean"},
|
||||
{"title": "Sunset Melody", "artist": "Acoustic Soul", "votes": "8", "position": "2", "imageUrl": "https://i.scdn.co/image/sunset"},
|
||||
{"title": "Peaceful Waters", "artist": "Nature Sounds", "votes": "5", "position": "3", "imageUrl": "https://i.scdn.co/image/water"},
|
||||
{"title": "Summer Nights", "artist": "Chill Vibes", "votes": "3", "position": "4", "imageUrl": "https://i.scdn.co/image/night"},
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: const Color(0xFF121212),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
children: [
|
||||
// Current Playing Section
|
||||
Expanded(
|
||||
flex: 2,
|
||||
return Consumer<MusicQueueService>(
|
||||
builder: (context, queueService, child) {
|
||||
final currentTrack = queueService.currentTrack;
|
||||
final queue = queueService.queue;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFF121212),
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// Album Art Placeholder
|
||||
// Now Playing Header
|
||||
Container(
|
||||
width: 200,
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF6366F1).withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: const Color(0xFF6366F1), width: 2),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.music_note,
|
||||
size: 80,
|
||||
color: Color(0xFF6366F1),
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: const Text(
|
||||
'Now Playing',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Song Info
|
||||
Text(
|
||||
currentSong,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
// Current Track Display
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height * 0.5,
|
||||
margin: const EdgeInsets.all(20),
|
||||
child: currentTrack != null
|
||||
? _buildCurrentTrackCard(context, currentTrack, queueService)
|
||||
: _buildNoTrackCard(),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
currentArtist,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
color: Colors.grey,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Progress Bar
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
// Playback Controls
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: _buildPlaybackControls(queueService),
|
||||
),
|
||||
|
||||
// Queue Preview
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height * 0.3,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
LinearProgressIndicator(
|
||||
value: progress,
|
||||
backgroundColor: Colors.grey[800],
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(Color(0xFF6366F1)),
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(bottom: 10),
|
||||
child: Text(
|
||||
'Up Next',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"${(progress * 3.5).toInt()}:${((progress * 3.5 % 1) * 60).toInt().toString().padLeft(2, '0')}",
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
const Text(
|
||||
"3:30",
|
||||
style: TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
],
|
||||
Expanded(
|
||||
child: queue.isEmpty
|
||||
? const Center(
|
||||
child: Text(
|
||||
'No songs in queue\nGo to Voting to add some!',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
itemCount: queue.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _buildQueueItem(queue[index], index + 1);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20), // Extra padding at bottom
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCurrentTrackCard(BuildContext context, SpotifyTrack currentTrack, MusicQueueService queueService) {
|
||||
return Card(
|
||||
color: const Color(0xFF1E1E1E),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// Album Art
|
||||
Container(
|
||||
width: 160,
|
||||
height: 160,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: const Color(0xFF2A2A2A),
|
||||
),
|
||||
child: currentTrack.album.images.isNotEmpty
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Image.network(
|
||||
currentTrack.album.images.first.url,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(
|
||||
Icons.music_note,
|
||||
size: 80,
|
||||
color: Colors.grey,
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
: const Icon(
|
||||
Icons.music_note,
|
||||
size: 80,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// Queue Section
|
||||
Expanded(
|
||||
flex: 1,
|
||||
// Track Info
|
||||
Text(
|
||||
currentTrack.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
currentTrack.artists.map((a) => a.name).join(', '),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
currentTrack.album.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
|
||||
// Progress Bar
|
||||
const SizedBox(height: 15),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
LinearProgressIndicator(
|
||||
value: queueService.progress,
|
||||
backgroundColor: Colors.grey[800],
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(Color(0xFF6366F1)),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
"Up Next",
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
Text(
|
||||
_formatDuration((queueService.progress * currentTrack.durationMs / 1000).round()),
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xFF22C55E),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
const Text(
|
||||
"Live Queue",
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF22C55E),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
Text(
|
||||
currentTrack.duration,
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: upcomingQueue.length,
|
||||
itemBuilder: (context, index) {
|
||||
final song = upcomingQueue[index];
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1E1E1E),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Queue Position
|
||||
Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
decoration: BoxDecoration(
|
||||
color: index < 2
|
||||
? const Color(0xFF6366F1)
|
||||
: const Color(0xFF6366F1).withOpacity(0.3),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'${index + 1}',
|
||||
style: TextStyle(
|
||||
color: index < 2 ? Colors.white : Colors.grey,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF6366F1).withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: song["imageUrl"] != null && song["imageUrl"]!.isNotEmpty
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Image.network(
|
||||
song["imageUrl"]!,
|
||||
width: 40,
|
||||
height: 40,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(
|
||||
Icons.music_note,
|
||||
color: Color(0xFF6366F1),
|
||||
size: 20,
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
: const Icon(
|
||||
Icons.music_note,
|
||||
color: Color(0xFF6366F1),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
song["title"]!,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
song["artist"]!,
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF6366F1).withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.thumb_up,
|
||||
color: Color(0xFF6366F1),
|
||||
size: 12,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
song["votes"]!,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF6366F1),
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -274,4 +204,114 @@ class _NowPlayingPageState extends State<NowPlayingPage> {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNoTrackCard() {
|
||||
return Card(
|
||||
color: const Color(0xFF1E1E1E),
|
||||
child: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.music_off,
|
||||
size: 80,
|
||||
color: Colors.grey,
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
'No track playing',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Text(
|
||||
'Add some songs from the Voting tab!',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPlaybackControls(MusicQueueService queueService) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
// Previous (disabled for now)
|
||||
IconButton(
|
||||
onPressed: null,
|
||||
icon: const Icon(Icons.skip_previous),
|
||||
iconSize: 40,
|
||||
color: Colors.grey,
|
||||
),
|
||||
|
||||
// Play/Pause
|
||||
IconButton(
|
||||
onPressed: queueService.togglePlayPause,
|
||||
icon: Icon(queueService.isPlaying ? Icons.pause_circle_filled : Icons.play_circle_filled),
|
||||
iconSize: 60,
|
||||
color: const Color(0xFF6366F1),
|
||||
),
|
||||
|
||||
// Next
|
||||
IconButton(
|
||||
onPressed: queueService.queue.isNotEmpty ? queueService.skipTrack : null,
|
||||
icon: const Icon(Icons.skip_next),
|
||||
iconSize: 40,
|
||||
color: queueService.queue.isNotEmpty ? Colors.white : Colors.grey,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQueueItem(QueueItem item, int position) {
|
||||
return Card(
|
||||
color: const Color(0xFF1E1E1E),
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: const Color(0xFF6366F1),
|
||||
child: Text(
|
||||
'$position',
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
item.track.name,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 14),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Text(
|
||||
item.track.artists.map((a) => a.name).join(', '),
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.thumb_up, color: Colors.green, size: 16),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'${item.votes}',
|
||||
style: const TextStyle(color: Colors.green, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDuration(int seconds) {
|
||||
int minutes = seconds ~/ 60;
|
||||
int remainingSeconds = seconds % 60;
|
||||
return '${minutes}:${remainingSeconds.toString().padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue