Fix mobile app submodule initialization and cleanup

- Removed incorrect swingmusic_mobile directory
- Properly initialized swingmusic_mobile submodule from swingmusic-mobile.git
- Clean submodule configuration for unified release workflow
This commit is contained in:
Tomas Dvorak
2026-03-18 19:32:08 +01:00
parent 9f1623bb34
commit 1d964f5ba8
159 changed files with 0 additions and 18429 deletions
@@ -1,442 +0,0 @@
import 'package:flutter/material.dart';
class AnalyticsScreen extends StatefulWidget {
const AnalyticsScreen({super.key});
@override
State<AnalyticsScreen> createState() => _AnalyticsScreenState();
}
class _AnalyticsScreenState extends State<AnalyticsScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Analytics'),
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Overview Cards
Row(
children: [
Expanded(
child: _buildOverviewCard(
'Total Plays',
Icons.play_arrow,
'12,345',
Theme.of(context).colorScheme.primary,
),
),
const SizedBox(width: 16),
Expanded(
child: _buildOverviewCard(
'Total Listening Time',
Icons.access_time,
'48h 32m',
Theme.of(context).colorScheme.secondary,
),
),
],
),
const SizedBox(height: 16),
// Top Tracks
_buildSectionHeader('Top Tracks'),
const SizedBox(height: 8),
_buildTopTracksList(),
const SizedBox(height: 24),
// Listening Stats
_buildSectionHeader('Listening Statistics'),
const SizedBox(height: 8),
_buildListeningStats(),
const SizedBox(height: 24),
// Genre Distribution
_buildSectionHeader('Genre Distribution'),
const SizedBox(height: 8),
_buildGenreChart(),
const SizedBox(height: 24),
// Time Distribution
_buildSectionHeader('Time Distribution'),
const SizedBox(height: 8),
_buildTimeChart(),
],
),
),
);
}
Widget _buildSectionHeader(String title) {
return Container(
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12.0),
),
child: Row(
children: [
Icon(
Icons.analytics,
color: Theme.of(context).colorScheme.primary,
size: 24,
),
const SizedBox(width: 12),
Text(
title,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
);
}
Widget _buildOverviewCard(String title, IconData icon, String value, Color color) {
return Container(
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(12.0),
border: Border.all(
color: Theme.of(context).colorScheme.outline,
width: 1.0,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
icon,
color: Theme.of(context).colorScheme.onPrimary,
size: 32,
),
const SizedBox(width: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
value,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
),
),
],
),
],
),
],
),
);
}
Widget _buildTopTracksList() {
final topTracks = [
{'title': 'Bohemian Rhapsody', 'artist': 'Queen', 'plays': 1234, 'duration': '5:55'},
{'title': 'Stairway to Heaven', 'artist': 'Led Zeppelin', 'plays': 987, 'duration': '8:02'},
{'title': 'Hotel California', 'artist': 'Eagles', 'plays': 856, 'duration': '3:31'},
{'title': 'Sweet Child O\' Mine', 'artist': 'Guns N\' Roses', 'plays': 743, 'duration': '5:44'},
{'title': 'Don\'t Stop Believin\'', 'artist': 'Journey', 'plays': 654, 'duration': '4:12'},
];
return Card(
margin: const EdgeInsets.only(bottom: 16.0),
child: Column(
children: [
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: topTracks.length,
itemBuilder: (context, index) {
final track = topTracks[index];
return ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context).colorScheme.primary,
child: Text(
'${index + 1}',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
title: Text(
track['title']?.toString() ?? '',
style: Theme.of(context).textTheme.titleMedium,
),
subtitle: Text(
track['artist']?.toString() ?? '',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
trailing: Text(
'${track['plays'] ?? 0} plays',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
);
},
),
],
),
);
}
Widget _buildListeningStats() {
return Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Daily Average',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: _buildStatItem('Songs per Day', '24'),
),
Expanded(
child: _buildStatItem('Hours per Day', '3.2'),
),
],
),
const SizedBox(height: 16),
Text(
'Weekly Average',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: _buildStatItem('Songs per Week', '168'),
),
Expanded(
child: _buildStatItem('Hours per Week', '22.4'),
),
],
),
const SizedBox(height: 16),
Text(
'Monthly Average',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: _buildStatItem('Songs per Month', '730'),
),
Expanded(
child: _buildStatItem('Hours per Month', '97.1'),
),
],
),
],
),
),
);
}
Widget _buildStatItem(String label, String value) {
return Container(
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(8.0),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
value,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
label,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
);
}
Widget _buildGenreChart() {
final genres = {
'Rock': 35,
'Pop': 28,
'Electronic': 15,
'Classical': 12,
'Jazz': 8,
'Hip-Hop': 7,
'Country': 5,
};
return Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Genre Distribution',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
SizedBox(
height: 200,
child: Wrap(
spacing: 8.0,
runSpacing: 8.0,
children: genres.entries.map((entry) {
return Chip(
label: Text(entry.key),
backgroundColor: _getGenreColor(entry.key),
labelStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
);
}).toList(),
),
),
],
),
),
);
}
Color _getGenreColor(String genre) {
switch (genre) {
case 'Rock':
return Colors.red;
case 'Pop':
return Colors.purple;
case 'Electronic':
return Colors.blue;
case 'Classical':
return Colors.brown;
case 'Jazz':
return Colors.orange;
case 'Hip-Hop':
return Colors.green;
case 'Country':
return Colors.amber;
default:
return Colors.grey;
}
}
Widget _buildTimeChart() {
final timeData = [
{'period': 'Morning', 'hours': 2.5, 'percentage': 15},
{'period': 'Afternoon', 'hours': 4.2, 'percentage': 25},
{'period': 'Evening', 'hours': 3.8, 'percentage': 22},
{'period': 'Night', 'hours': 7.5, 'percentage': 38},
];
return Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Daily Listening Pattern',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
SizedBox(
height: 200,
child: Column(
children: timeData.map((data) {
return Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
data['period']?.toString() ?? '',
style: Theme.of(context).textTheme.bodyMedium,
),
Text(
'${data['percentage']}%',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
],
),
Container(
height: 8,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
borderRadius: BorderRadius.circular(4.0),
),
child: FractionallySizedBox(
widthFactor: (data['percentage'] as int) / 100,
alignment: Alignment.centerLeft,
child: Container(
height: 4,
color: Colors.white,
),
),
),
],
),
);
}).toList(),
),
),
],
),
),
);
}
}
@@ -1,88 +0,0 @@
import 'package:flutter/material.dart';
class AuthScreen extends StatefulWidget {
const AuthScreen({super.key});
@override
State<AuthScreen> createState() => _AuthScreenState();
}
class _AuthScreenState extends State<AuthScreen> {
bool _isLoading = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Authentication'),
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.music_note,
size: 80,
color: Colors.blue,
),
const SizedBox(height: 24),
const Text(
'SwingMusic',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
const Text(
'Connect to your music library',
style: TextStyle(
fontSize: 16,
color: Colors.grey,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 32),
ElevatedButton(
onPressed: _isLoading ? null : _handleLogin,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
child: _isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation(Colors.white),
),
)
: const Text('Login'),
),
],
),
),
);
}
void _handleLogin() async {
setState(() {
_isLoading = true;
});
await Future.delayed(const Duration(seconds: 2));
setState(() {
_isLoading = false;
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Login successful!')),
);
Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false);
}
}
@@ -1,468 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/auth_provider.dart';
import '../../core/constants/app_spacing.dart';
import '../../core/enums/auth_state.dart';
class EnhancedAuthScreen extends StatefulWidget {
const EnhancedAuthScreen({super.key});
@override
State<EnhancedAuthScreen> createState() => _EnhancedAuthScreenState();
}
class _EnhancedAuthScreenState extends State<EnhancedAuthScreen> {
final _formKey = GlobalKey<FormState>();
final _baseUrlController = TextEditingController();
final _usernameController = TextEditingController();
final _passwordController = TextEditingController();
final _qrCodeController = TextEditingController();
bool _isPasswordVisible = false;
bool _isLoading = false;
bool _isQrMode = false;
String? _errorMessage;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
Provider.of<AuthProvider>(context, listen: false).initialize();
});
}
@override
void dispose() {
_baseUrlController.dispose();
_usernameController.dispose();
_passwordController.dispose();
_qrCodeController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
body: SafeArea(
child: SingleChildScrollView(
padding: AppSpacing.paddingLG,
child: Column(
children: [
// Logo and Title
_buildHeader(context),
const SizedBox(height: 32),
// Auth Mode Toggle
_buildAuthModeToggle(context),
const SizedBox(height: 32),
// Auth Form
_buildAuthForm(context),
const SizedBox(height: 24),
// Error Message
if (_errorMessage != null)
_buildErrorMessage(context),
],
),
),
),
);
}
Widget _buildHeader(BuildContext context) {
return Column(
children: [
Icon(
Icons.music_note,
size: 80,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(height: 16),
Text(
'SwingMusic',
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.onSurface,
),
),
const SizedBox(height: 8),
Text(
'Connect to your music library',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
textAlign: TextAlign.center,
),
],
);
}
Widget _buildAuthModeToggle(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: () => setState(() => _isQrMode = false),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 16),
decoration: BoxDecoration(
color: _isQrMode
? Theme.of(context).colorScheme.surface
: Theme.of(context).colorScheme.primary,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(12),
bottomLeft: Radius.circular(12),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.person,
color: _isQrMode
? Theme.of(context).colorScheme.onSurfaceVariant
: Theme.of(context).colorScheme.onPrimary,
),
const SizedBox(width: 8),
Text(
'Username & Password',
style: TextStyle(
color: _isQrMode
? Theme.of(context).colorScheme.onSurfaceVariant
: Theme.of(context).colorScheme.onPrimary,
fontWeight: FontWeight.w500,
),
),
],
),
),
),
),
Expanded(
child: GestureDetector(
onTap: () => setState(() => _isQrMode = true),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 16),
decoration: BoxDecoration(
color: _isQrMode
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(12),
bottomRight: Radius.circular(12),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.qr_code_scanner,
color: _isQrMode
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(width: 8),
Text(
'QR Code',
style: TextStyle(
color: _isQrMode
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onSurfaceVariant,
fontWeight: FontWeight.w500,
),
),
],
),
),
),
),
],
),
);
}
Widget _buildAuthForm(BuildContext context) {
return Consumer<AuthProvider>(
builder: (context, authProvider, child) {
return Form(
key: _formKey,
child: Column(
children: [
if (_isQrMode) ...[
// QR Code Input
TextFormField(
controller: _qrCodeController,
decoration: InputDecoration(
labelText: 'QR Code',
hintText: 'Enter or scan QR code',
prefixIcon: const Icon(Icons.qr_code_scanner),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.outline,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.primary,
),
),
),
readOnly: true,
onTap: () => _scanQrCode(context),
),
] else ...[
// Server URL Input
TextFormField(
controller: _baseUrlController,
decoration: InputDecoration(
labelText: 'Server URL',
hintText: 'https://your-server.com',
prefixIcon: const Icon(Icons.link),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.outline,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.primary,
),
),
),
validator: (value) {
if (value == null || value!.isEmpty) {
return 'Server URL is required';
}
if (!_isValidUrl(value)) {
return 'Please enter a valid URL';
}
return null;
},
),
const SizedBox(height: 16),
// Username Input
TextFormField(
controller: _usernameController,
decoration: InputDecoration(
labelText: 'Username',
hintText: 'Enter your username',
prefixIcon: const Icon(Icons.person),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.outline,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.primary,
),
),
),
validator: (value) {
if (value == null || value!.isEmpty) {
return 'Username is required';
}
return null;
},
),
const SizedBox(height: 16),
// Password Input
TextFormField(
controller: _passwordController,
obscureText: !_isPasswordVisible,
decoration: InputDecoration(
labelText: 'Password',
hintText: 'Enter your password',
prefixIcon: const Icon(Icons.lock),
suffixIcon: IconButton(
onPressed: () => setState(() => _isPasswordVisible = !_isPasswordVisible),
icon: Icon(
_isPasswordVisible ? Icons.visibility : Icons.visibility_off,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.outline,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.primary,
),
),
),
validator: (value) {
if (value == null || value!.isEmpty) {
return 'Password is required';
}
return null;
},
),
],
const SizedBox(height: 24),
// Login Button
SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: _isLoading ? null : () => _handleLogin(context),
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: _isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation(Colors.white),
),
)
: Text(
_isQrMode ? 'Login with QR' : 'Login',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
],
),
);
},
);
}
Widget _buildErrorMessage(BuildContext context) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.errorContainer,
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Icon(
Icons.error_outline,
color: Theme.of(context).colorScheme.error,
size: 20,
),
const SizedBox(width: 8),
Expanded(
child: Text(
_errorMessage!,
style: TextStyle(
color: Theme.of(context).colorScheme.error,
fontSize: 14,
),
),
),
IconButton(
onPressed: () => setState(() => _errorMessage = null),
icon: const Icon(Icons.close),
iconSize: 16,
color: Theme.of(context).colorScheme.error,
),
],
),
);
}
bool _isValidUrl(String url) {
try {
final uri = Uri.parse(url);
return uri.hasScheme && (uri.scheme == 'http' || uri.scheme == 'https');
} catch (e) {
return false;
}
}
Future<void> _handleLogin(BuildContext context) async {
if (!_formKey.currentState!.validate()) {
return;
}
setState(() {
_isLoading = true;
_errorMessage = null;
});
try {
final authProvider = Provider.of<AuthProvider>(context, listen: false);
if (_isQrMode) {
await authProvider.loginWithQrCode(_qrCodeController.text.trim());
} else {
await authProvider.loginWithUsernameAndPassword(
_baseUrlController.text.trim(),
_usernameController.text.trim(),
_passwordController.text,
);
}
if (mounted) {
Navigator.of(context).pushReplacementNamed('/home');
}
} catch (e) {
setState(() {
_isLoading = false;
_errorMessage = e.toString();
});
}
}
Future<void> _scanQrCode(BuildContext context) async {
try {
final qrCode = await Navigator.pushNamed<String>('/qr');
if (qrCode != null && mounted) {
_qrCodeController.text = qrCode!;
}
} catch (e) {
setState(() {
_errorMessage = 'Failed to scan QR code: $e';
});
}
}
}
@@ -1,889 +0,0 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/audio_provider.dart';
import '../../data/models/track_model.dart';
class FolderScreen extends StatefulWidget {
const FolderScreen({super.key});
@override
State<FolderScreen> createState() => _FolderScreenState();
}
class _FolderScreenState extends State<FolderScreen> {
List<FolderItem> _folderItems = [];
List<FolderItem> _currentPath = [];
bool _isLoading = false;
final TextEditingController _searchController = TextEditingController();
String _currentFolderId = 'root';
@override
void initState() {
super.initState();
_loadFolderContents(_currentFolderId);
}
@override
void dispose() {
_searchController.dispose();
super.dispose();
}
Future<void> _loadFolderContents(String folderId) async {
setState(() {
_isLoading = true;
});
// Simulate API call
await Future.delayed(const Duration(milliseconds: 500));
setState(() {
_isLoading = false;
if (folderId == 'root') {
_currentPath = [];
_folderItems = [
FolderItem(
id: 'music',
name: 'Music',
type: FolderType.folder,
itemCount: 156,
path: '/music',
modifiedDate: DateTime.now().subtract(const Duration(days: 1)),
),
FolderItem(
id: 'downloads',
name: 'Downloads',
type: FolderType.folder,
itemCount: 42,
path: '/downloads',
modifiedDate: DateTime.now().subtract(const Duration(hours: 3)),
),
FolderItem(
id: 'rock',
name: 'Rock',
type: FolderType.folder,
itemCount: 89,
path: '/music/rock',
modifiedDate: DateTime.now().subtract(const Duration(days: 7)),
),
FolderItem(
id: 'pop',
name: 'Pop',
type: FolderType.folder,
itemCount: 67,
path: '/music/pop',
modifiedDate: DateTime.now().subtract(const Duration(days: 2)),
),
FolderItem(
id: 'jazz',
name: 'Jazz',
type: FolderType.folder,
itemCount: 34,
path: '/music/jazz',
modifiedDate: DateTime.now().subtract(const Duration(days: 14)),
),
FolderItem(
id: 'electronic',
name: 'Electronic',
type: FolderType.folder,
itemCount: 78,
path: '/music/electronic',
modifiedDate: DateTime.now().subtract(const Duration(days: 5)),
),
FolderItem(
id: 'classical',
name: 'Classical',
type: FolderType.folder,
itemCount: 45,
path: '/music/classical',
modifiedDate: DateTime.now().subtract(const Duration(days: 21)),
),
];
} else if (folderId == 'music') {
_currentPath = [
FolderItem(id: 'root', name: '..', type: FolderType.folder, path: '/'),
FolderItem(id: 'rock', name: 'Rock', type: FolderType.folder, itemCount: 89, path: '/music/rock'),
FolderItem(id: 'pop', name: 'Pop', type: FolderType.folder, itemCount: 67, path: '/music/pop'),
FolderItem(id: 'jazz', name: 'Jazz', type: FolderType.folder, itemCount: 34, path: '/music/jazz'),
FolderItem(id: 'electronic', name: 'Electronic', type: FolderType.folder, itemCount: 78, path: '/music/electronic'),
FolderItem(id: 'classical', name: 'Classical', type: FolderType.folder, itemCount: 45, path: '/music/classical'),
];
_folderItems = [
TrackFolderItem(
id: '1',
name: 'Bohemian Rhapsody.mp3',
artist: 'Queen',
album: 'A Night at the Opera',
duration: 334,
size: 5.2,
modifiedDate: DateTime.now().subtract(const Duration(days: 30)),
),
TrackFolderItem(
id: '2',
name: 'Stairway to Heaven.mp3',
artist: 'Led Zeppelin',
album: 'Led Zeppelin IV',
duration: 482,
size: 7.8,
modifiedDate: DateTime.now().subtract(const Duration(days: 25)),
),
TrackFolderItem(
id: '3',
name: 'Hotel California.mp3',
artist: 'Eagles',
album: 'Hotel California',
duration: 391,
size: 6.1,
modifiedDate: DateTime.now().subtract(const Duration(days: 20)),
),
TrackFolderItem(
id: '4',
name: 'Sweet Child O\' Mine.mp3',
artist: 'Queen',
album: 'A Night at the Opera',
duration: 348,
size: 5.4,
modifiedDate: DateTime.now().subtract(const Duration(days: 15)),
),
TrackFolderItem(
id: '5',
name: 'Another Brick in the Wall.mp3',
artist: 'Pink Floyd',
album: 'The Wall',
duration: 623,
size: 9.8,
modifiedDate: DateTime.now().subtract(const Duration(days: 10)),
),
];
} else {
// Handle other folders with sample data
_currentPath = [
FolderItem(id: 'root', name: '..', type: FolderType.folder, path: '/'),
];
_folderItems = [
TrackFolderItem(
id: '1',
name: 'Sample Track.mp3',
artist: 'Sample Artist',
album: 'Sample Album',
duration: 240,
size: 4.2,
modifiedDate: DateTime.now().subtract(const Duration(days: 5)),
),
];
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(_getFolderTitle()),
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
leading: _currentFolderId != 'root'
? IconButton(
onPressed: () => _navigateToFolder('root'),
icon: const Icon(Icons.arrow_back),
)
: null,
actions: [
PopupMenuButton<String>(
onSelected: _handleMenuAction,
itemBuilder: (context) => [
const PopupMenuItem(
value: 'sort_name',
child: ListTile(
leading: const Icon(Icons.sort_by_alpha),
title: Text('Sort by Name'),
contentPadding: EdgeInsets.zero,
),
),
const PopupMenuItem(
value: 'sort_date',
child: ListTile(
leading: const Icon(Icons.access_time),
title: Text('Sort by Date'),
contentPadding: EdgeInsets.zero,
),
),
const PopupMenuItem(
value: 'sort_size',
child: ListTile(
leading: const Icon(Icons.storage),
title: Text('Sort by Size'),
contentPadding: EdgeInsets.zero,
),
),
const PopupMenuItem(
value: 'view_list',
child: ListTile(
leading: const Icon(Icons.list),
title: Text('List View'),
contentPadding: EdgeInsets.zero,
),
),
const PopupMenuItem(
value: 'view_grid',
child: ListTile(
leading: const Icon(Icons.grid_view),
title: Text('Grid View'),
contentPadding: EdgeInsets.zero,
),
),
],
),
],
),
body: Column(
children: [
// Breadcrumb Navigation
_buildBreadcrumbNavigation(),
// Search Bar
Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
controller: _searchController,
decoration: InputDecoration(
hintText: 'Search in current folder...',
prefixIcon: const Icon(Icons.search),
suffixIcon: _searchController.text.isNotEmpty
? IconButton(
onPressed: () {
_searchController.clear();
},
icon: const Icon(Icons.clear),
)
: null,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Theme.of(context).colorScheme.surfaceContainerHighest,
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
),
onChanged: (value) {
_filterItems(value);
},
),
),
// Folder Contents
Expanded(
child: _isLoading
? const Center(child: CircularProgressIndicator())
: _folderItems.isEmpty
? _buildEmptyState()
: _buildFolderContents(),
),
],
),
);
}
Widget _buildBreadcrumbNavigation() {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
// Root/Home
InkWell(
onTap: () => _navigateToFolder('root'),
borderRadius: BorderRadius.circular(8),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: _currentFolderId == 'root'
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.home,
size: 20,
color: _currentFolderId == 'root'
? Theme.of(context).colorScheme.onPrimaryContainer
: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(width: 8),
Text(
'Home',
style: TextStyle(
color: _currentFolderId == 'root'
? Theme.of(context).colorScheme.onPrimaryContainer
: Theme.of(context).colorScheme.onSurfaceVariant,
fontWeight: FontWeight.w500,
),
),
],
),
),
),
// Breadcrumb items
..._currentPath.map((item) {
return Padding(
padding: const EdgeInsets.only(left: 4),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.chevron_right, size: 16),
const SizedBox(width: 4),
InkWell(
onTap: () => _navigateToFolder(item.id),
borderRadius: BorderRadius.circular(8),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: item.id == _currentFolderId
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Text(
item.name,
style: TextStyle(
color: item.id == _currentFolderId
? Theme.of(context).colorScheme.onPrimaryContainer
: Theme.of(context).colorScheme.onSurfaceVariant,
fontWeight: FontWeight.w500,
),
),
),
),
],
),
);
}).toList(),
],
),
),
);
}
Widget _buildFolderContents() {
return ListView.builder(
padding: const EdgeInsets.all(8.0),
itemCount: _folderItems.length,
itemBuilder: (context, index) {
final item = _folderItems[index];
if (item is TrackFolderItem) {
return TrackFolderTile(
track: item,
onTap: () => _playTrack(item),
onPlay: () => _playTrack(item),
);
} else {
return FolderTile(
folder: item,
onTap: () => _navigateToFolder(item.id),
onLongPress: () => _showFolderOptions(item),
);
}
},
);
}
Widget _buildEmptyState() {
return Center(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.folder_open,
size: 64,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(height: 16),
Text(
'This folder is empty',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 8),
Text(
'Add music files to see them here',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
],
),
),
);
}
String _getFolderTitle() {
if (_currentFolderId == 'root') {
return 'Music Library';
} else {
final folder = _currentPath.firstWhere(
(item) => item.id == _currentFolderId,
orElse: () => FolderItem(id: '', name: '', type: FolderType.folder),
);
return folder.name;
}
}
void _filterItems(String query) {
setState(() {
if (query.isEmpty) {
_loadFolderContents(_currentFolderId);
} else {
// Filter items (in real app, this would call API)
_folderItems = _folderItems.where((item) {
final name = item.name.toLowerCase();
return name.contains(query.toLowerCase());
}).toList();
}
});
}
void _navigateToFolder(String folderId) {
setState(() {
_currentFolderId = folderId;
});
_loadFolderContents(folderId);
}
void _playTrack(TrackFolderItem track) {
final trackModel = TrackModel(
id: int.parse(track.id),
title: track.name,
album: track.album,
albumhash: track.album.hashCode.toString(),
artists: [],
albumartists: [],
artisthashes: [],
track: 0,
disc: 1,
duration: track.duration,
bitrate: 320,
filepath: track.id, // Use ID as filepath for demo
folder: '',
genres: [],
genrehashes: [],
copyright: '',
date: DateTime.now().millisecondsSinceEpoch ~/ 1000,
lastModified: DateTime.now().millisecondsSinceEpoch ~/ 1000,
trackhash: track.id,
image: '',
weakHash: '',
extra: {},
lastplayed: 0,
playcount: 0,
playduration: track.duration,
explicit: false,
favUserids: [],
isFavorite: false,
score: 0.0,
);
final audioProvider = Provider.of<AudioProvider>(context, listen: false);
audioProvider.setQueue([trackModel]);
audioProvider.loadTrack(trackModel);
audioProvider.play();
Navigator.pushNamed(context, '/player');
}
void _handleMenuAction(String action) {
switch (action) {
case 'sort_name':
setState(() {
_folderItems.sort((a, b) => a.name.compareTo(b.name));
});
break;
case 'sort_date':
setState(() {
_folderItems.sort((a, b) => b.modifiedDate!.compareTo(a.modifiedDate!));
});
break;
case 'sort_size':
setState(() {
_folderItems.sort((a, b) {
final sizeA = a is TrackFolderItem ? a.size : 0;
final sizeB = b is TrackFolderItem ? b.size : 0;
return sizeA.compareTo(sizeB);
});
});
break;
// View options would be handled here
}
}
void _showFolderOptions(FolderItem folder) {
showModalBottomSheet(
context: context,
builder: (context) => Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.play_arrow),
title: const Text('Play All'),
onTap: () {
Navigator.pop(context);
_playAllInFolder();
},
),
ListTile(
leading: const Icon(Icons.shuffle),
title: const Text('Shuffle All'),
onTap: () {
Navigator.pop(context);
_shuffleAllInFolder();
},
),
ListTile(
leading: const Icon(Icons.playlist_add),
title: const Text('Add to Playlist'),
onTap: () {
Navigator.pop(context);
_addToPlaylist();
},
),
const SizedBox(height: 8),
ListTile(
leading: Icon(
Icons.delete,
color: Theme.of(context).colorScheme.error,
),
title: Text(
'Delete',
style: TextStyle(
color: Theme.of(context).colorScheme.error,
),
),
onTap: () {
Navigator.pop(context);
_deleteFolder();
},
),
],
),
),
);
}
void _playAllInFolder() {
// Implementation to play all tracks in folder
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Playing all tracks in folder')),
);
}
void _shuffleAllInFolder() {
// Implementation to shuffle all tracks in folder
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Shuffling all tracks in folder')),
);
}
void _addToPlaylist() {
// Implementation to add folder contents to playlist
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Added to playlist')),
);
}
void _deleteFolder() {
// Implementation to delete folder
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Folder deleted')),
);
}
}
// Helper classes
class FolderItem {
final String id;
final String name;
final FolderType type;
final int? itemCount;
final String? path;
final DateTime? modifiedDate;
FolderItem({
required this.id,
required this.name,
required this.type,
this.itemCount,
this.path,
this.modifiedDate,
});
}
class TrackFolderItem extends FolderItem {
final String artist;
final String album;
final int duration;
final double size;
TrackFolderItem({
required String id,
required String name,
required this.artist,
required this.album,
required this.duration,
required this.size,
String? path,
DateTime? modifiedDate,
}) : super(
id: id,
name: name,
type: FolderType.track,
path: path,
modifiedDate: modifiedDate ?? DateTime.now(),
);
}
enum FolderType {
folder,
track,
}
// Custom widgets
class FolderTile extends StatelessWidget {
final FolderItem folder;
final VoidCallback onTap;
final VoidCallback? onLongPress;
const FolderTile({
super.key,
required this.folder,
required this.onTap,
this.onLongPress,
});
@override
Widget build(BuildContext context) {
return Card(
child: InkWell(
onTap: onTap,
onLongPress: onLongPress,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
// Folder/Track Icon
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: folder.type == FolderType.folder
? Theme.of(context).colorScheme.primary.withOpacity(0.1)
: Theme.of(context).colorScheme.secondary.withOpacity(0.1),
borderRadius: BorderRadius.circular(8.0),
),
child: Icon(
folder.type == FolderType.folder ? Icons.folder : Icons.music_note,
color: folder.type == FolderType.folder
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.secondary,
),
),
const SizedBox(width: 16),
// Folder/Track Info
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
folder.name,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
if (folder.itemCount != null)
Text(
'${folder.itemCount} items',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
if (folder.modifiedDate != null)
Text(
_formatDate(folder.modifiedDate!),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
if (folder is TrackFolderItem)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
(folder as TrackFolderItem).artist,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
Text(
(folder as TrackFolderItem).album,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
],
),
),
],
),
),
),
);
}
}
class TrackFolderTile extends StatelessWidget {
final TrackFolderItem track;
final VoidCallback onTap;
final VoidCallback? onPlay;
const TrackFolderTile({
super.key,
required this.track,
required this.onTap,
this.onPlay,
});
@override
Widget build(BuildContext context) {
return Card(
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
// Track Icon
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondary.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Icon(
Icons.music_note,
color: Theme.of(context).colorScheme.secondary,
),
),
const SizedBox(width: 16),
// Track Info
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
track.name,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Text(
track.artist,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
Text(
track.album,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 8),
Row(
children: [
Text(
_formatDuration(track.duration),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(width: 8),
Text(
'${track.size.toStringAsFixed(1)} MB',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
],
),
),
// Play Button
IconButton(
onPressed: onPlay,
icon: const Icon(Icons.play_arrow),
color: Theme.of(context).colorScheme.primary,
),
],
),
),
),
);
}
}
String _formatDate(DateTime date) {
final now = DateTime.now();
final difference = now.difference(date);
if (difference.inDays == 0) {
return 'Today';
} else if (difference.inDays == 1) {
return 'Yesterday';
} else if (difference.inDays < 7) {
return '${difference.inDays} days ago';
} else if (difference.inDays < 30) {
return '${(difference.inDays / 7).floor()} weeks ago';
} else {
return '${(difference.inDays / 30).floor()} months ago';
}
}
String _formatDuration(int seconds) {
final minutes = seconds ~/ 60;
final remainingSeconds = seconds % 60;
return '${minutes}:${remainingSeconds.toString().padLeft(2, '0')}';
}
@@ -1,407 +0,0 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/audio_provider.dart';
import '../../shared/providers/library_provider.dart';
import '../../core/widgets/album_card.dart';
import '../../core/widgets/track_list_tile.dart';
import '../../data/models/track_model.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
late LibraryProvider _libraryProvider;
late AudioProvider _audioProvider;
bool _isLoading = false;
@override
void initState() {
super.initState();
_libraryProvider = Provider.of<LibraryProvider>(context, listen: false);
_audioProvider = Provider.of<AudioProvider>(context, listen: false);
_loadHomeData();
}
Future<void> _loadHomeData() async {
setState(() {
_isLoading = true;
});
try {
// Load recent data from library
await Future.wait([
_libraryProvider.loadTracks(limit: 10),
_libraryProvider.loadAlbums(limit: 5),
_libraryProvider.loadArtists(limit: 5),
]);
} catch (e) {
// Handle error silently for now
}
setState(() {
_isLoading = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: [
// App Bar
SliverAppBar(
floating: true,
snap: true,
backgroundColor: Theme.of(context).colorScheme.surface,
elevation: 0,
title: Text(
'SwingMusic',
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
actions: [
IconButton(
onPressed: () {
// Show notifications
},
icon: const Icon(Icons.notifications_outlined),
),
PopupMenuButton<String>(
icon: CircleAvatar(
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
child: Icon(
Icons.person,
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
),
onSelected: (value) {
if (value == 'settings') {
Navigator.pushNamed(context, '/settings');
}
},
itemBuilder: (context) => [
const PopupMenuItem(
value: 'settings',
child: Row(
children: [
Icon(Icons.settings),
SizedBox(width: 8),
Text('Settings'),
],
),
),
],
),
],
),
// Quick Actions Section
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Quick Actions',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: _buildQuickActionCard(
icon: Icons.search,
label: 'Search',
color: Theme.of(context).colorScheme.primary,
onTap: () {
Navigator.pushNamed(context, '/search');
},
),
),
const SizedBox(width: 12),
Expanded(
child: _buildQuickActionCard(
icon: Icons.library_music,
label: 'Library',
color: Theme.of(context).colorScheme.secondary,
onTap: () {
Navigator.pushNamed(context, '/library');
},
),
),
],
),
const SizedBox(height: 12),
Row(
children: [
Expanded(
child: _buildQuickActionCard(
icon: Icons.favorite,
label: 'Favorites',
color: Colors.red,
onTap: () {
Navigator.pushNamed(context, '/library');
},
),
),
const SizedBox(width: 12),
Expanded(
child: _buildQuickActionCard(
icon: Icons.download,
label: 'Downloads',
color: Colors.green,
onTap: () {
// Navigate to downloads
},
),
),
],
),
],
),
),
),
// Recently Played Section
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Recently Played',
style: Theme.of(context).textTheme.titleLarge,
),
TextButton(
onPressed: () {
Navigator.pushNamed(context, '/library');
},
child: const Text('See all'),
),
],
),
const SizedBox(height: 16),
if (_isLoading)
const Center(child: CircularProgressIndicator())
else if (_libraryProvider.tracks.isEmpty)
_buildEmptySection('No recently played tracks')
else
SizedBox(
height: 200,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _libraryProvider.tracks.length.clamp(0, 10),
itemBuilder: (context, index) {
final track = _libraryProvider.tracks[index];
return Container(
width: 160,
margin: const EdgeInsets.only(right: 12),
child: TrackListTile(
track: track,
onTap: () => _playTrack(track),
onPlay: () => _playTrack(track),
showAlbumArt: true,
),
);
},
),
),
],
),
),
),
// Recent Albums Section
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Recent Albums',
style: Theme.of(context).textTheme.titleLarge,
),
TextButton(
onPressed: () {
Navigator.pushNamed(context, '/library');
},
child: const Text('See all'),
),
],
),
const SizedBox(height: 16),
if (_isLoading)
const Center(child: CircularProgressIndicator())
else if (_libraryProvider.albums.isEmpty)
_buildEmptySection('No recent albums')
else
GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.8,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
itemCount: _libraryProvider.albums.length.clamp(0, 4),
itemBuilder: (context, index) {
final album = _libraryProvider.albums[index];
return AlbumCard(
album: album,
onTap: () {
// Navigate to album details
},
);
},
),
],
),
),
),
// Top Artists Section
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Top Artists',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
if (_isLoading)
const Center(child: CircularProgressIndicator())
else if (_libraryProvider.artists.isEmpty)
_buildEmptySection('No top artists')
else
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: _libraryProvider.artists.length.clamp(0, 5),
itemBuilder: (context, index) {
final artist = _libraryProvider.artists[index];
return ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
child: Text(
artist.name.isNotEmpty ? artist.name[0].toUpperCase() : '?',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer,
fontWeight: FontWeight.bold,
),
),
),
title: Text(artist.name),
trailing: const Icon(Icons.arrow_forward_ios),
onTap: () {
// Navigate to artist details
},
);
},
),
],
),
),
),
// Bottom padding
const SliverToBoxAdapter(
child: SizedBox(height: 100), // Space for mini player
),
],
),
);
}
Widget _buildQuickActionCard({
required IconData icon,
required String label,
required Color color,
required VoidCallback onTap,
}) {
return Card(
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Icon(
icon,
color: color,
size: 28,
),
),
const SizedBox(height: 12),
Text(
label,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
),
],
),
),
),
);
}
Widget _buildEmptySection(String message) {
return Container(
padding: const EdgeInsets.all(32),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12),
),
child: Column(
children: [
Icon(
Icons.music_note_outlined,
size: 48,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(height: 12),
Text(
message,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
);
}
void _playTrack(TrackModel track) {
_audioProvider.setQueue([track]);
_audioProvider.loadTrack(track);
_audioProvider.play();
Navigator.pushNamed(context, '/player');
}
}
@@ -1,363 +0,0 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/audio_provider.dart';
import '../../shared/providers/library_provider.dart';
import '../../core/widgets/album_card.dart';
import '../../core/widgets/track_list_tile.dart';
import '../../data/models/track_model.dart';
class LibraryScreen extends StatefulWidget {
const LibraryScreen({super.key});
@override
State<LibraryScreen> createState() => _LibraryScreenState();
}
class _LibraryScreenState extends State<LibraryScreen>
with SingleTickerProviderStateMixin {
late TabController _tabController;
late LibraryProvider _libraryProvider;
late AudioProvider _audioProvider;
bool _isLoading = false;
@override
void initState() {
super.initState();
_tabController = TabController(length: 6, vsync: this);
_libraryProvider = Provider.of<LibraryProvider>(context, listen: false);
_audioProvider = Provider.of<AudioProvider>(context, listen: false);
_loadLibraryData();
}
Future<void> _loadLibraryData() async {
setState(() {
_isLoading = true;
});
try {
await Future.wait([
_libraryProvider.loadTracks(),
_libraryProvider.loadAlbums(),
_libraryProvider.loadArtists(),
_libraryProvider.loadFavorites(),
]);
} catch (e) {
// Handle error silently for now
}
setState(() {
_isLoading = false;
});
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
// Header
Container(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Your Library',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
// Search bar
TextField(
decoration: InputDecoration(
hintText: 'Search your library...',
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
filled: true,
fillColor: Theme.of(context).colorScheme.surfaceContainerHighest,
),
),
],
),
),
// Tabs
TabBar(
controller: _tabController,
isScrollable: true,
tabs: const [
Tab(text: 'Recent'),
Tab(text: 'Albums'),
Tab(text: 'Tracks'),
Tab(text: 'Folders'),
Tab(text: 'Favorites'),
Tab(text: 'Playlists'),
],
),
// Tab content
Expanded(
child: TabBarView(
controller: _tabController,
children: [
_buildRecentTab(),
_buildAlbumsTab(),
_buildTracksTab(),
_buildFoldersTab(),
_buildFavoritesTab(),
_buildPlaylistsTab(),
],
),
),
],
),
);
}
Widget _buildRecentTab() {
if (_isLoading) {
return const Center(child: CircularProgressIndicator());
}
return SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Recently Played',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
if (_libraryProvider.tracks.isEmpty)
_buildEmptyState('No recently played tracks')
else
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: _libraryProvider.tracks.length,
itemBuilder: (context, index) {
final track = _libraryProvider.tracks[index];
return TrackListTile(
track: track,
onTap: () => _playTrack(track),
onPlay: () => _playTrack(track),
isPlaying: _isCurrentTrack(track),
);
},
),
],
),
);
}
Widget _buildAlbumsTab() {
if (_isLoading) {
return const Center(child: CircularProgressIndicator());
}
return SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Albums',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
if (_libraryProvider.albums.isEmpty)
_buildEmptyState('No albums found')
else
GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.8,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
itemCount: _libraryProvider.albums.length,
itemBuilder: (context, index) {
final album = _libraryProvider.albums[index];
return AlbumCard(
album: album,
onTap: () {
// Navigate to album details
},
);
},
),
],
),
);
}
Widget _buildTracksTab() {
if (_isLoading) {
return const Center(child: CircularProgressIndicator());
}
return SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'All Tracks',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
if (_libraryProvider.tracks.isEmpty)
_buildEmptyState('No tracks found')
else
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: _libraryProvider.tracks.length,
itemBuilder: (context, index) {
final track = _libraryProvider.tracks[index];
return TrackListTile(
track: track,
onTap: () => _playTrack(track),
onPlay: () => _playTrack(track),
isPlaying: _isCurrentTrack(track),
);
},
),
],
),
);
}
Widget _buildFavoritesTab() {
if (_isLoading) {
return const Center(child: CircularProgressIndicator());
}
return SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Favorite Tracks',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
if (_libraryProvider.favoriteTracks.isEmpty)
_buildEmptyState('No favorite tracks yet')
else
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: _libraryProvider.favoriteTracks.length,
itemBuilder: (context, index) {
final track = _libraryProvider.favoriteTracks[index];
return TrackListTile(
track: track,
onTap: () => _playTrack(track),
onPlay: () => _playTrack(track),
isPlaying: _isCurrentTrack(track),
);
},
),
],
),
);
}
Widget _buildFoldersTab() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.folder,
size: 64,
color: Theme.of(context).colorScheme.onSurface,
),
const SizedBox(height: 16),
Text(
'Folder navigation coming soon',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.normal,
color: Theme.of(context).colorScheme.onSurface,
),
textAlign: TextAlign.center,
),
],
),
);
}
Widget _buildPlaylistsTab() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.playlist_play,
size: 64,
color: Theme.of(context).colorScheme.onSurface,
),
const SizedBox(height: 16),
Text(
'Playlist management coming soon',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.normal,
color: Theme.of(context).colorScheme.onSurface,
),
textAlign: TextAlign.center,
),
],
),
);
}
Widget _buildEmptyState(String message) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.music_note,
size: 64,
color: Theme.of(context).colorScheme.onSurface,
),
const SizedBox(height: 16),
Text(
message,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.normal,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
);
}
void _playTrack(TrackModel track) {
_audioProvider.setQueue([track]);
_audioProvider.loadTrack(track);
_audioProvider.play();
Navigator.pushNamed(context, '/player');
}
bool _isCurrentTrack(TrackModel track) {
return _audioProvider.currentTrack?.trackhash == track.trackhash;
}
}
@@ -1,482 +0,0 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/audio_provider.dart';
import '../../data/services/lyrics_service.dart';
import '../../core/constants/app_spacing.dart';
class LyricsScreen extends StatefulWidget {
const LyricsScreen({super.key});
@override
State<LyricsScreen> createState() => _LyricsScreenState();
}
class _LyricsScreenState extends State<LyricsScreen> {
bool _isLoading = false;
String? _lyrics;
String? _error;
final TextEditingController _lyricsController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.surface,
elevation: 0,
title: Text(
'Lyrics',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.w600,
),
),
leading: IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: Icon(
Icons.close,
color: Theme.of(context).colorScheme.onSurface,
),
),
),
body: Consumer<AudioProvider>(
builder: (context, audioProvider, child) {
final currentTrack = audioProvider.currentTrack;
if (currentTrack == null) {
return _buildEmptyState(context);
}
return Column(
children: [
// Track Info
Container(
padding: AppSpacing.paddingLG,
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
currentTrack.displayTitle,
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.w600,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
Text(
currentTrack.artistNames,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
if (currentTrack.displayAlbum.isNotEmpty) ...[
const SizedBox(height: 4),
Text(
currentTrack.displayAlbum,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
],
),
),
const SizedBox(width: 16),
// Album Art
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
blurRadius: 8,
offset: const Offset(0, 4),
),
],
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: currentTrack.image.isNotEmpty
? Image.network(
currentTrack.image,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Theme.of(context).colorScheme.primary.withOpacity(0.8),
Theme.of(context).colorScheme.primary,
],
),
),
child: Icon(
Icons.music_note,
color: Theme.of(context).colorScheme.onPrimary,
size: 32,
),
);
},
)
: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Theme.of(context).colorScheme.primary.withOpacity(0.8),
Theme.of(context).colorScheme.primary,
],
),
),
child: Icon(
Icons.album,
color: Theme.of(context).colorScheme.onPrimary,
size: 32,
),
),
),
),
],
),
),
const SizedBox(height: 24),
// Sync Button
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () => _loadLyrics(context, currentTrack?.trackhash ?? ''),
icon: Icon(
Icons.sync,
color: Theme.of(context).colorScheme.onPrimary,
),
label: 'Sync Lyrics',
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
),
),
),
const SizedBox(height: 24),
// Lyrics Content
Expanded(
child: Container(
padding: AppSpacing.paddingLG,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.3),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (_isLoading) ...[
const Center(
child: CircularProgressIndicator(),
),
] else if (_error != null) ...[
Container(
padding: AppSpacing.paddingMD,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.errorContainer,
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Icon(
Icons.error_outline,
color: Theme.of(context).colorScheme.error,
size: 20,
),
const SizedBox(width: 12),
Expanded(
child: Text(
_error!,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.error,
),
),
),
],
),
),
] else if (_lyrics != null && _lyrics!.isNotEmpty) ...[
// Edit Mode
if (_isEditMode) ...[
_buildEditMode(context),
] else ...[
// Display Mode
_buildLyricsDisplay(context),
],
] else ...[
Container(
padding: AppSpacing.paddingXL,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.lyrics,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
size: 48,
),
const SizedBox(height: 16),
Text(
'No lyrics available',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
textAlign: TextAlign.center,
),
],
),
),
],
],
),
),
),
],
);
},
),
);
}
Widget _buildEmptyState(BuildContext context) {
return Container(
padding: AppSpacing.paddingXL,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.music_note,
size: 64,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
const SizedBox(height: 16),
Text(
'No lyrics available',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
'Play a track to see its lyrics',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
textAlign: TextAlign.center,
),
],
),
);
}
Widget _buildLyricsDisplay(BuildContext context) {
return Container(
padding: AppSpacing.paddingMD,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header with Edit button
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Lyrics',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.w600,
),
),
Row(
children: [
// Edit/Save buttons
if (_isEditMode) ...[
IconButton(
onPressed: () => _saveLyrics(context),
icon: Icon(
Icons.save,
color: Theme.of(context).colorScheme.primary,
size: 20,
),
),
IconButton(
onPressed: () => _cancelEdit(context),
icon: Icon(
Icons.close,
color: Theme.of(context).colorScheme.onSurface,
size: 20,
),
),
] else ...[
IconButton(
onPressed: () => _enableEditMode(context),
icon: Icon(
Icons.edit,
color: Theme.of(context).colorScheme.primary,
size: 20,
),
),
],
],
// Sync button
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () => _syncLyrics(context),
icon: Icon(
Icons.refresh,
color: Theme.of(context).colorScheme.onPrimary,
),
label: 'Sync',
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
),
),
],
),
),
// Lyrics text
Expanded(
child: SingleChildScrollView(
child: Text(
_lyrics!,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
height: 1.6,
color: Theme.of(context).colorScheme.onSurface,
leading: TextStyle(
height: 1.4,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
),
),
),
),
],
),
);
}
Widget _buildEditMode(BuildContext context) {
return Container(
padding: AppSpacing.paddingMD,
child: Row(
children: [
Expanded(
child: TextField(
controller: _lyricsController,
maxLines: null,
style: TextStyle(
height: 1.6,
color: Theme.of(context).colorScheme.onSurface,
),
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.primary,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.primary,
width: 2,
),
),
),
),
),
IconButton(
onPressed: () => _saveLyrics(context),
icon: Icon(
Icons.save,
color: Theme.of(context).colorScheme.primary,
),
),
],
),
);
}
bool get _isEditMode => _lyricsController.text != _lyrics;
void _enableEditMode() {
_lyricsController.text = _lyrics ?? '';
setState(() {});
}
void _cancelEdit() {
_lyricsController.text = _lyrics ?? '';
setState(() {});
}
void _saveLyrics(BuildContext context) {
final updatedLyrics = _lyricsController.text.trim();
// TODO: Save lyrics to API
setState(() {
_lyrics = updatedLyrics;
_isEditMode = false;
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Lyrics saved successfully'),
backgroundColor: Colors.green,
),
);
}
Future<void> _loadLyrics(BuildContext context, String trackHash) async {
setState(() {
_isLoading = true;
_error = null;
});
try {
final lyricsService = LyricsService();
final lyrics = await lyricsService.getLyrics(trackHash);
setState(() {
_isLoading = false;
_lyrics = lyrics;
});
} catch (e) {
setState(() {
_isLoading = false;
_error = 'Failed to load lyrics: $e';
});
}
}
void _syncLyrics(BuildContext context) {
final currentTrack = Provider.of<AudioProvider>(context, listen: false).currentTrack;
if (currentTrack != null) return;
_loadLyrics(context, currentTrack.trackhash);
}
}
@@ -1,374 +0,0 @@
import 'package:flutter/material.dart';
class OfflineScreen extends StatefulWidget {
const OfflineScreen({super.key});
@override
State<OfflineScreen> createState() => _OfflineScreenState();
}
class _OfflineScreenState extends State<OfflineScreen> {
bool _isOfflineMode = false;
final List<Map<String, dynamic>> _downloadedTracks = [];
int _totalDownloads = 0;
int _completedDownloads = 0;
double _totalDownloadSize = 0.0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Offline Mode'),
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
actions: [
Switch(
value: _isOfflineMode,
onChanged: (value) {
setState(() {
_isOfflineMode = value;
});
},
activeThumbColor: Theme.of(context).colorScheme.primary,
activeTrackColor: Theme.of(context).colorScheme.onPrimary,
),
],
),
body: Column(
children: [
// Offline Mode Toggle Card
Container(
margin: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12.0),
border: Border.all(
color: Theme.of(context).colorScheme.outline,
width: 1.0,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.cloud_off,
color: _isOfflineMode
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurfaceVariant,
size: 24,
),
const SizedBox(width: 12),
Text(
'Offline Mode',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 8),
Text(
_isOfflineMode
? 'Download music for offline listening'
: 'Connect to server for online mode',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
),
const SizedBox(height: 16),
// Downloads Section
Expanded(
child: Container(
margin: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12.0),
border: Border.all(
color: Theme.of(context).colorScheme.outline,
width: 1.0,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Downloads Header
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Downloads',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
IconButton(
onPressed: _clearDownloads,
icon: const Icon(Icons.clear_all),
tooltip: 'Clear All',
),
],
),
const SizedBox(height: 16),
// Download Stats
Container(
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(8.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildStatCard('Total', _totalDownloads.toString(), Icons.download),
_buildStatCard('Completed', _completedDownloads.toString(), Icons.check_circle),
_buildStatCard('Size', _formatFileSize(_totalDownloadSize), Icons.storage),
],
),
),
const SizedBox(height: 16),
// Downloaded Tracks List
Expanded(
child: _downloadedTracks.isEmpty
? _buildEmptyState()
: _buildDownloadsList(),
),
],
),
),
),
],
),
);
}
Widget _buildStatCard(String title, String value, IconData icon) {
return Container(
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(8.0),
),
child: Column(
children: [
Icon(
icon,
color: Theme.of(context).colorScheme.onPrimaryContainer,
size: 24,
),
const SizedBox(height: 8),
Text(
title,
style: Theme.of(context).textTheme.labelMedium?.copyWith(
color: Theme.of(context).colorScheme.onPrimaryContainer,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
value,
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
),
],
),
);
}
Widget _buildEmptyState() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.download_outlined,
size: 64,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(height: 16),
Text(
'No downloads yet',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: _simulateDownload,
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.download),
const SizedBox(width: 8),
const Text('Download Sample Track'),
],
),
),
],
),
);
}
Widget _buildDownloadsList() {
return ListView.builder(
padding: const EdgeInsets.all(8.0),
itemCount: _downloadedTracks.length,
itemBuilder: (context, index) {
final track = _downloadedTracks[index];
return Card(
margin: const EdgeInsets.only(bottom: 8.0),
child: ListTile(
leading: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainer,
),
child: track['isOffline'] == true
? const Icon(Icons.offline_pin, color: Colors.green)
: const Icon(Icons.music_note, color: Colors.blue),
),
),
title: Text(
track['title']?.toString() ?? 'Unknown Track',
style: Theme.of(context).textTheme.titleMedium,
),
subtitle: Text(
track['artist']?.toString() ?? 'Unknown Artist',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
_formatFileSize(track['size']?.toDouble() ?? 0.0),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(width: 8),
PopupMenuButton<String>(
onSelected: (value) {
_handleTrackAction(track, value);
},
itemBuilder: (context) => [
const PopupMenuItem(
value: 'play',
child: Row(
children: [
const Icon(Icons.play_arrow, size: 16),
const SizedBox(width: 8),
const Text('Play'),
],
),
),
const PopupMenuItem(
value: 'delete',
child: Row(
children: [
const Icon(Icons.delete, size: 16, color: Colors.red),
const SizedBox(width: 8),
const Text('Delete'),
],
),
),
],
),
],
),
),
);
},
);
}
String _formatFileSize(double bytes) {
if (bytes < 1024) {
return '${bytes.toStringAsFixed(0)} B';
} else if (bytes < 1024 * 1024) {
return '${(bytes / 1024).toStringAsFixed(1)} KB';
} else if (bytes < 1024 * 1024 * 1024) {
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
} else {
return '${(bytes / (1024 * 1024 * 1024)).toStringAsFixed(1)} GB';
}
}
void _clearDownloads() {
setState(() {
_downloadedTracks.clear();
_totalDownloads = 0;
_completedDownloads = 0;
_totalDownloadSize = 0.0;
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('All downloads cleared')),
);
}
void _simulateDownload() {
setState(() {
_totalDownloads++;
_completedDownloads++;
final trackSize = 5.2 * 1024 * 1024; // 5.2 MB
_totalDownloadSize += trackSize;
_downloadedTracks.add({
'id': 'track_${_totalDownloads}',
'title': 'Sample Track $_totalDownloads',
'artist': 'Sample Artist',
'album': 'Sample Album',
'duration': '3:45',
'size': trackSize,
'isOffline': true,
'downloadDate': DateTime.now().toIso8601String(),
});
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Sample track downloaded')),
);
}
void _handleTrackAction(Map<String, dynamic> track, String action) {
switch (action) {
case 'play':
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Playing: ${track['title']}')),
);
break;
case 'delete':
setState(() {
_downloadedTracks.remove(track);
_totalDownloads--;
if (track['isOffline'] == true) {
_completedDownloads--;
_totalDownloadSize -= (track['size'] ?? 0.0);
}
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Deleted: ${track['title']}')),
);
break;
}
}
}
@@ -1,427 +0,0 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/audio_provider.dart';
import '../../core/constants/app_spacing.dart';
import '../../core/enums/playback_mode.dart';
class EnhancedPlayerScreen extends StatefulWidget {
const EnhancedPlayerScreen({super.key});
@override
State<EnhancedPlayerScreen> createState() => _EnhancedPlayerScreenState();
}
class _EnhancedPlayerScreenState extends State<EnhancedPlayerScreen> {
@override
Widget build(BuildContext context) {
return Consumer<AudioProvider>(
builder: (context, audioProvider, child) {
final currentTrack = audioProvider.currentTrack;
if (currentTrack == null) {
return _buildEmptyPlayer();
}
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Theme.of(context).colorScheme.surface,
Theme.of(context).colorScheme.surface.withOpacity(0.95),
],
),
),
child: SafeArea(
child: Column(
children: [
// Top Bar
Padding(
padding: AppSpacing.horizontalMD,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: Icon(
Icons.keyboard_arrow_down,
color: Theme.of(context).colorScheme.onSurface,
),
),
Text(
'Now Playing',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.onSurface,
),
),
IconButton(
onPressed: () => _showMoreOptions(context),
icon: Icon(
Icons.more_vert,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
),
// Album Artwork
Expanded(
flex: 3,
child: Padding(
padding: AppSpacing.horizontalLG,
child: _buildAlbumArtwork(context, currentTrack),
),
),
// Track Info & Controls
Expanded(
flex: 2,
child: Padding(
padding: AppSpacing.horizontalLG,
child: Column(
children: [
// Track Info
_buildTrackInfo(context, currentTrack),
const SizedBox(height: 24),
// Progress Bar
_buildProgressBar(context, audioProvider),
const SizedBox(height: 24),
// Playback Controls
_buildPlaybackControls(context, audioProvider),
const SizedBox(height: 16),
// Bottom Controls
_buildBottomControls(context, audioProvider),
],
),
),
],
),
),
),
);
},
);
}
Widget _buildAlbumArtwork(BuildContext context, dynamic currentTrack) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: currentTrack.image.isNotEmpty
? Image.network(
currentTrack.image,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return _buildDefaultAlbumArt(context);
},
)
: _buildDefaultAlbumArt(context),
),
);
}
Widget _buildTrackInfo(BuildContext context, dynamic currentTrack) {
return Column(
children: [
Text(
currentTrack.displayTitle,
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.onSurface,
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
Text(
currentTrack.artistNames,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
if (currentTrack.displayAlbum.isNotEmpty) ...[
const SizedBox(height: 4),
Text(
currentTrack.displayAlbum,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
],
);
}
Widget _buildProgressBar(BuildContext context, AudioProvider audioProvider) {
return Column(
children: [
SliderTheme(
data: SliderTheme.of(context).copyWith(
thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 8),
trackHeight: 4,
activeTrackColor: Theme.of(context).colorScheme.primary,
inactiveTrackColor: Theme.of(context).colorScheme.surfaceVariant,
),
child: Slider(
value: audioProvider.progress,
onChanged: (value) {
final newPosition = Duration(
milliseconds: (value * audioProvider.duration.inMilliseconds).round(),
);
audioProvider.seekTo(newPosition);
},
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
audioProvider.positionFormatted,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
),
Text(
audioProvider.durationFormatted,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
),
],
),
),
],
);
}
Widget _buildPlaybackControls(BuildContext context, AudioProvider audioProvider) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// Shuffle
IconButton(
onPressed: () => audioProvider.toggleShuffle(),
icon: Icon(
Icons.shuffle,
color: audioProvider.shuffleMode == ShuffleMode.on
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
// Previous
IconButton(
onPressed: () => audioProvider.playPrevious(),
icon: Icon(
Icons.skip_previous,
color: Theme.of(context).colorScheme.onSurface,
),
iconSize: 40,
),
// Play/Pause with buffering indicator
_buildPlayPauseButton(context, audioProvider),
// Next
IconButton(
onPressed: () => audioProvider.playNext(),
icon: Icon(
Icons.skip_next,
color: Theme.of(context).colorScheme.onSurface,
),
iconSize: 40,
),
// Repeat
IconButton(
onPressed: () => audioProvider.toggleRepeat(),
icon: _getRepeatIcon(audioProvider.repeatMode),
color: audioProvider.repeatMode != RepeatMode.off
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
],
);
}
Widget _buildPlayPauseButton(BuildContext context, AudioProvider audioProvider) {
return Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.primary,
),
child: Stack(
alignment: Alignment.center,
children: [
IconButton(
onPressed: () {
if (audioProvider.isPlaying) {
audioProvider.pause();
} else {
audioProvider.play();
}
},
icon: Icon(
audioProvider.isPlaying ? Icons.pause : Icons.play_arrow,
color: Theme.of(context).colorScheme.onPrimary,
size: 48,
),
),
if (audioProvider.isBuffering)
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.primary.withOpacity(0.8),
),
child: const CircularProgressIndicator(
strokeWidth: 3,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
),
],
),
);
}
Widget _buildBottomControls(BuildContext context, AudioProvider audioProvider) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// Favorite
IconButton(
onPressed: () => _toggleFavorite(context, audioProvider),
icon: Icon(
audioProvider.currentTrack?.isFavorite == true
? Icons.favorite
: Icons.favorite_border,
color: audioProvider.currentTrack?.isFavorite == true
? Colors.red
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
// Queue
IconButton(
onPressed: () => _showQueue(context),
icon: Icon(
Icons.queue_music,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
// Volume
IconButton(
onPressed: () => _showVolumeSlider(context, audioProvider),
icon: Icon(
Icons.volume_up,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
}
IconData _getRepeatIcon(RepeatMode mode) {
switch (mode) {
case RepeatMode.one:
return Icons.repeat_one;
case RepeatMode.all:
return Icons.repeat;
case RepeatMode.off:
default:
return Icons.repeat;
}
}
void _toggleFavorite(BuildContext context, AudioProvider audioProvider) {
// Toggle favorite functionality
}
void _showQueue(BuildContext context) {
// Show queue functionality
}
void _showVolumeSlider(BuildContext context, AudioProvider audioProvider) {
showModalBottomSheet(
context: context,
builder: (context) => Container(
padding: AppSpacing.paddingLG,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Volume',
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 16),
Slider(
value: audioProvider.volume,
onChanged: (value) => audioProvider.setVolume(value),
min: 0.0,
max: 1.0,
),
],
),
),
);
}
void _showMoreOptions(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (context) => Container(
padding: AppSpacing.large,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.share),
title: const Text('Share'),
onTap: () => Navigator.pop(context),
),
ListTile(
leading: const Icon(Icons.playlist_add),
title: const Text('Add to Playlist'),
onTap: () => Navigator.pop(context),
),
ListTile(
leading: const Icon(Icons.info_outline),
title: const Text('Track Info'),
onTap: () => Navigator.pop(context),
),
],
),
),
);
}
@@ -1,489 +0,0 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/audio_provider.dart';
import '../../core/constants/app_spacing.dart';
import '../../core/enums/playback_mode.dart';
class EnhancedPlayerScreen extends StatefulWidget {
const EnhancedPlayerScreen({super.key});
@override
State<EnhancedPlayerScreen> createState() => _EnhancedPlayerScreenState();
}
class _EnhancedPlayerScreenState extends State<EnhancedPlayerScreen> {
@override
Widget build(BuildContext context) {
return Consumer<AudioProvider>(
builder: (context, audioProvider, child) {
final currentTrack = audioProvider.currentTrack;
if (currentTrack == null) {
return _buildEmptyPlayer();
}
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Theme.of(context).colorScheme.surface,
Theme.of(context).colorScheme.surface.withOpacity(0.95),
],
),
),
child: SafeArea(
child: Column(
children: [
// Top Bar
Padding(
padding: AppSpacing.horizontalMD,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: Icon(
Icons.keyboard_arrow_down,
color: Theme.of(context).colorScheme.onSurface,
),
),
Text(
'Now Playing',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.onSurface,
),
),
IconButton(
onPressed: () => _showMoreOptions(context),
icon: Icon(
Icons.more_vert,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
),
// Album Artwork
Expanded(
flex: 3,
child: Padding(
padding: AppSpacing.horizontalLG,
child: _buildAlbumArtwork(context, currentTrack),
),
),
// Track Info & Controls
Expanded(
flex: 2,
child: Padding(
padding: AppSpacing.horizontalLG,
child: Column(
children: [
// Track Info
_buildTrackInfo(context, currentTrack),
const SizedBox(height: 24),
// Progress Bar
_buildProgressBar(context, audioProvider),
const SizedBox(height: 24),
// Playback Controls
_buildPlaybackControls(context, audioProvider),
const SizedBox(height: 16),
// Bottom Controls
_buildBottomControls(context, audioProvider),
],
),
),
],
),
),
),
);
},
);
}
Widget _buildAlbumArtwork(BuildContext context, dynamic currentTrack) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: currentTrack.image.isNotEmpty
? Image.network(
currentTrack.image,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return _buildDefaultAlbumArt(context);
},
)
: _buildDefaultAlbumArt(context),
),
);
}
Widget _buildTrackInfo(BuildContext context, dynamic currentTrack) {
return Column(
children: [
Text(
currentTrack.displayTitle,
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.onSurface,
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
Text(
currentTrack.artistNames,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
if (currentTrack.displayAlbum.isNotEmpty) ...[
const SizedBox(height: 4),
Text(
currentTrack.displayAlbum,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
],
);
}
Widget _buildProgressBar(BuildContext context, AudioProvider audioProvider) {
return Column(
children: [
SliderTheme(
data: SliderTheme.of(context).copyWith(
thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 8),
trackHeight: 4,
activeTrackColor: Theme.of(context).colorScheme.primary,
inactiveTrackColor: Theme.of(context).colorScheme.surfaceVariant,
),
child: Slider(
value: audioProvider.progress,
onChanged: (value) {
final newPosition = Duration(
milliseconds: (value * audioProvider.duration.inMilliseconds).round(),
);
audioProvider.seekTo(newPosition);
},
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
audioProvider.positionFormatted,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
),
Text(
audioProvider.durationFormatted,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
),
],
),
),
],
);
}
Widget _buildPlaybackControls(BuildContext context, AudioProvider audioProvider) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// Shuffle
IconButton(
onPressed: () => audioProvider.toggleShuffle(),
icon: Icon(
Icons.shuffle,
color: audioProvider.shuffleMode == ShuffleMode.on
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
// Previous
IconButton(
onPressed: () => audioProvider.playPrevious(),
icon: Icon(
Icons.skip_previous,
color: Theme.of(context).colorScheme.onSurface,
),
iconSize: 40,
),
// Play/Pause with buffering indicator
_buildPlayPauseButton(context, audioProvider),
// Next
IconButton(
onPressed: () => audioProvider.playNext(),
icon: Icon(
Icons.skip_next,
color: Theme.of(context).colorScheme.onSurface,
),
iconSize: 40,
),
// Repeat
IconButton(
onPressed: () => audioProvider.toggleRepeat(),
icon: _getRepeatIcon(audioProvider.repeatMode),
color: audioProvider.repeatMode != RepeatMode.off
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
],
);
}
Widget _buildPlayPauseButton(BuildContext context, AudioProvider audioProvider) {
return Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.primary,
),
child: Stack(
alignment: Alignment.center,
children: [
IconButton(
onPressed: () {
if (audioProvider.isPlaying) {
audioProvider.pause();
} else {
audioProvider.play();
}
},
icon: Icon(
audioProvider.isPlaying ? Icons.pause : Icons.play_arrow,
color: Theme.of(context).colorScheme.onPrimary,
size: 48,
),
),
if (audioProvider.isBuffering)
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.primary.withOpacity(0.8),
),
child: const CircularProgressIndicator(
strokeWidth: 3,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
),
],
),
);
}
Widget _buildBottomControls(BuildContext context, AudioProvider audioProvider) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// Favorite
IconButton(
onPressed: () => _toggleFavorite(context, audioProvider),
icon: Icon(
audioProvider.currentTrack?.isFavorite == true
? Icons.favorite
: Icons.favorite_border,
color: audioProvider.currentTrack?.isFavorite == true
? Colors.red
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
// Queue
IconButton(
onPressed: () => _showQueue(context),
icon: Icon(
Icons.queue_music,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
// Volume
IconButton(
onPressed: () => _showVolumeSlider(context, audioProvider),
icon: Icon(
Icons.volume_up,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
// More options
IconButton(
onPressed: () => _showMoreOptions(context),
icon: Icon(
Icons.more_horiz,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
],
);
}
Widget _buildDefaultAlbumArt(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Theme.of(context).colorScheme.primary.withOpacity(0.7),
Theme.of(context).colorScheme.secondary.withOpacity(0.7),
],
),
),
child: Icon(
Icons.album,
size: 120,
color: Theme.of(context).colorScheme.onPrimary,
),
);
}
Widget _buildEmptyPlayer() {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.music_note,
size: 64,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
const SizedBox(height: 16),
Text(
'No track playing',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
),
),
const SizedBox(height: 8),
Text(
'Select a track from your library to start playing',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
textAlign: TextAlign.center,
),
],
),
),
);
}
IconData _getRepeatIcon(RepeatMode mode) {
switch (mode) {
case RepeatMode.one:
return Icons.repeat_one;
case RepeatMode.all:
return Icons.repeat;
case RepeatMode.off:
return Icons.repeat;
}
}
void _toggleFavorite(BuildContext context, AudioProvider audioProvider) {
// Toggle favorite functionality
}
void _showQueue(BuildContext context) {
// Show queue functionality
}
void _showVolumeSlider(BuildContext context, AudioProvider audioProvider) {
showModalBottomSheet(
context: context,
builder: (context) => Container(
padding: AppSpacing.paddingLG,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Volume',
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 16),
Slider(
value: audioProvider.volume,
onChanged: (value) => audioProvider.setVolume(value),
min: 0.0,
max: 1.0,
),
],
),
),
);
}
void _showMoreOptions(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (context) => Container(
padding: AppSpacing.paddingLG,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.share),
title: const Text('Share'),
onTap: () => Navigator.pop(context),
),
ListTile(
leading: const Icon(Icons.playlist_add),
title: const Text('Add to Playlist'),
onTap: () => Navigator.pop(context),
),
ListTile(
leading: const Icon(Icons.info_outline),
title: const Text('Track Info'),
onTap: () => Navigator.pop(context),
),
],
),
),
);
}
}
@@ -1,373 +0,0 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/audio_provider.dart';
import '../../core/constants/app_spacing.dart';
class PlayerScreen extends StatefulWidget {
const PlayerScreen({super.key});
@override
State<PlayerScreen> createState() => _PlayerScreenState();
}
class _PlayerScreenState extends State<PlayerScreen> {
@override
void initState() {
super.initState();
// Initialize audio service if not already done
WidgetsBinding.instance.addPostFrameCallback((_) {
Provider.of<AudioProvider>(context, listen: false).initialize();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Consumer<AudioProvider>(
builder: (context, audioProvider, child) {
final currentTrack = audioProvider.currentTrack;
if (currentTrack == null) {
return _buildEmptyPlayer();
}
return Column(
children: [
// App Bar
SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.keyboard_arrow_down),
),
Text(
'Now Playing',
style: Theme.of(context).textTheme.titleMedium,
),
IconButton(
onPressed: () {
// Show more options
},
icon: const Icon(Icons.more_vert),
),
],
),
),
),
// Album Art
Expanded(
flex: 3,
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Theme.of(context).colorScheme.primary.withOpacity(0.7),
Theme.of(context).colorScheme.secondary.withOpacity(0.7),
],
),
),
child: currentTrack.image.isNotEmpty
? Image.network(
currentTrack.image,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return _buildDefaultAlbumArt(context);
},
)
: _buildDefaultAlbumArt(context),
),
),
),
),
),
// Track Info
Expanded(
flex: 1,
child: Padding(
padding: AppSpacing.horizontalXL,
child: Column(
children: [
Text(
currentTrack.displayTitle,
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
Text(
currentTrack.artistNames,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
if (currentTrack.displayAlbum.isNotEmpty) ...[
const SizedBox(height: 4),
Text(
currentTrack.displayAlbum,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
],
),
),
),
// Progress Bar
Padding(
padding: AppSpacing.horizontalXL,
child: Column(
children: [
SliderTheme(
data: SliderTheme.of(context).copyWith(
thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 8),
trackHeight: 4,
),
child: Slider(
value: audioProvider.progress,
onChanged: (value) {
final newPosition = Duration(
milliseconds: (value * audioProvider.duration.inMilliseconds).round(),
);
audioProvider.seekTo(newPosition);
},
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
audioProvider.positionFormatted,
style: Theme.of(context).textTheme.bodySmall,
),
Text(
audioProvider.durationFormatted,
style: Theme.of(context).textTheme.bodySmall,
),
// Volume Control
Expanded(
child: Row(
children: [
Icon(
Icons.volume_up,
color: Theme.of(context).colorScheme.onSurfaceVariant,
size: 20,
),
Expanded(
child: Slider(
value: audioProvider.volume,
onChanged: (value) {
audioProvider.setVolume(value);
},
min: 0.0,
max: 1.0,
),
),
],
),
),
],
),
),
],
),
),
// Playback Controls
Expanded(
flex: 1,
child: Padding(
padding: AppSpacing.horizontalXL,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// Shuffle
IconButton(
onPressed: () => audioProvider.toggleShuffle(),
icon: Icon(
Icons.shuffle,
color: audioProvider.isShuffleMode
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
// Previous
IconButton(
onPressed: () => audioProvider.playPrevious(),
icon: const Icon(Icons.skip_previous),
iconSize: 32,
),
// Play/Pause
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.primary,
),
child: IconButton(
onPressed: () {
if (audioProvider.isPlaying) {
audioProvider.pause();
} else {
audioProvider.play();
}
},
icon: audioProvider.isLoading
? const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: Icon(
audioProvider.isPlaying ? Icons.pause : Icons.play_arrow,
color: Theme.of(context).colorScheme.onPrimary,
size: 32,
),
),
),
// Next
IconButton(
onPressed: () => audioProvider.playNext(),
icon: const Icon(Icons.skip_next),
iconSize: 32,
),
// Repeat
IconButton(
onPressed: () => audioProvider.toggleRepeat(),
icon: Icon(
audioProvider.isRepeatMode ? Icons.repeat_one : Icons.repeat,
color: audioProvider.isRepeatMode
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
),
),
// Bottom Controls
Padding(
padding: const EdgeInsets.only(bottom: 32.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
onPressed: () {
// Add to favorites
},
icon: const Icon(Icons.favorite_border),
),
IconButton(
onPressed: () {
// Show playlist
},
icon: const Icon(Icons.playlist_play),
),
IconButton(
onPressed: () {
// Share
},
icon: const Icon(Icons.share),
),
],
),
),
],
);
},
),
);
}
Widget _buildEmptyPlayer() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.music_note,
size: 64,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(height: 16),
Text(
'No track playing',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 8),
Text(
'Select a track from your library to start playing',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
],
),
);
}
Widget _buildDefaultAlbumArt(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Theme.of(context).colorScheme.primary.withOpacity(0.7),
Theme.of(context).colorScheme.secondary.withOpacity(0.7),
],
),
),
child: Icon(
Icons.album,
size: 120,
color: Theme.of(context).colorScheme.onPrimary,
),
);
}
}
@@ -1,437 +0,0 @@
import 'package:flutter/material.dart';
import '../../data/models/playlist_model.dart';
class PlaylistsScreen extends StatefulWidget {
const PlaylistsScreen({super.key});
@override
State<PlaylistsScreen> createState() => _PlaylistsScreenState();
}
class _PlaylistsScreenState extends State<PlaylistsScreen> {
List<PlaylistModel> _playlists = [];
bool _isLoading = false;
final TextEditingController _playlistNameController = TextEditingController();
final TextEditingController _searchController = TextEditingController();
@override
void initState() {
super.initState();
_loadPlaylists();
}
@override
void dispose() {
_playlistNameController.dispose();
_searchController.dispose();
super.dispose();
}
Future<void> _loadPlaylists() async {
setState(() {
_isLoading = true;
});
// Simulate API call
await Future.delayed(const Duration(seconds: 1));
setState(() {
_isLoading = false;
// Sample playlists for demo
_playlists = [
PlaylistModel(
id: '1',
name: 'My Favorites',
description: 'My favorite tracks',
trackcount: 25,
isPublic: false,
createdDate: DateTime.now().subtract(const Duration(days: 30)),
lastModified: DateTime.now().subtract(const Duration(days: 5)),
),
PlaylistModel(
id: '2',
name: 'Workout Mix',
description: 'High energy tracks for workouts',
trackcount: 18,
isPublic: false,
createdDate: DateTime.now().subtract(const Duration(days: 15)),
lastModified: DateTime.now().subtract(const Duration(days: 2)),
),
PlaylistModel(
id: '3',
name: 'Chill Vibes',
description: 'Relaxing and focus music',
trackcount: 32,
isPublic: true,
createdDate: DateTime.now().subtract(const Duration(days: 7)),
lastModified: DateTime.now().subtract(const Duration(days: 1)),
),
PlaylistModel(
id: '4',
name: 'Road Trip Classics',
description: 'Classic hits for long drives',
trackcount: 45,
isPublic: false,
createdDate: DateTime.now().subtract(const Duration(days: 90)),
lastModified: DateTime.now().subtract(const Duration(days: 10)),
),
];
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Playlists'),
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
actions: [
IconButton(
onPressed: _showCreatePlaylistDialog,
icon: const Icon(Icons.add),
),
],
),
body: Column(
children: [
// Search Bar
Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
controller: _searchController,
decoration: InputDecoration(
hintText: 'Search playlists...',
prefixIcon: const Icon(Icons.search),
suffixIcon: _searchController.text.isNotEmpty
? IconButton(
onPressed: () {
_searchController.clear();
_filterPlaylists('');
},
icon: const Icon(Icons.clear),
)
: null,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Theme.of(context).colorScheme.surfaceContainerHighest,
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
),
onChanged: (value) {
_filterPlaylists(value);
},
),
),
// Playlists Grid
Expanded(
child: _isLoading
? const Center(child: CircularProgressIndicator())
: _playlists.isEmpty
? _buildEmptyState()
: _buildPlaylistsGrid(),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: _showCreatePlaylistDialog,
child: const Icon(Icons.add),
),
);
}
Widget _buildPlaylistsGrid() {
return GridView.builder(
padding: const EdgeInsets.all(16.0),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.8,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
itemCount: _playlists.length,
itemBuilder: (context, index) {
final playlist = _playlists[index];
return Card(
child: InkWell(
onTap: () => _openPlaylist(playlist),
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Playlist Cover
Container(
width: double.infinity,
height: 120,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Theme.of(context).colorScheme.primary.withValues(alpha: 0.8),
Theme.of(context).colorScheme.secondary.withValues(alpha: 0.8),
],
),
borderRadius: BorderRadius.circular(8),
),
child: Stack(
children: [
// Playlist Icon
Positioned(
top: 8,
right: 8,
child: Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.black.withValues(alpha: 0.7),
borderRadius: BorderRadius.circular(4),
),
child: Icon(
Icons.playlist_play,
color: Colors.white,
size: 20,
),
),
),
// Public/Private Badge
if (playlist.isPublic)
Positioned(
bottom: 8,
left: 8,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(8),
),
child: Text(
'PUBLIC',
style: const TextStyle(
color: Colors.white,
fontSize: 8,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
),
const SizedBox(height: 12),
// Playlist Info
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
playlist.name,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Text(
playlist.description,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
Row(
children: [
Icon(
Icons.music_note,
size: 16,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(width: 4),
Text(
'${playlist.trackcount} tracks',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
const SizedBox(height: 4),
Text(
_formatDate(playlist.lastModified),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
),
],
),
),
),
);
},
);
}
Widget _buildEmptyState() {
return Center(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.playlist_add,
size: 64,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(height: 16),
Text(
'No playlists yet',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 8),
Text(
'Create your first playlist to get started',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: _showCreatePlaylistDialog,
icon: const Icon(Icons.add),
label: const Text('Create Playlist'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
),
),
],
),
),
);
}
void _filterPlaylists(String query) {
setState(() {
if (query.isEmpty) {
// Reset to all playlists
_loadPlaylists();
} else {
// Filter playlists (in real app, this would call API)
_playlists = _playlists.where((playlist) =>
playlist.name.toLowerCase().contains(query.toLowerCase())
).toList();
}
});
}
void _openPlaylist(PlaylistModel playlist) {
Navigator.pushNamed(context, '/playlist', arguments: playlist);
}
void _showCreatePlaylistDialog() {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Create Playlist'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: _playlistNameController,
decoration: const InputDecoration(
labelText: 'Playlist Name',
border: OutlineInputBorder(),
),
autofocus: true,
),
const SizedBox(height: 16),
TextField(
decoration: const InputDecoration(
labelText: 'Description (Optional)',
border: OutlineInputBorder(),
),
maxLines: 3,
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: _createPlaylist,
child: const Text('Create'),
),
],
),
);
}
void _createPlaylist() async {
final name = _playlistNameController.text.trim();
if (name.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Please enter a playlist name')),
);
return;
}
// Create playlist (in real app, this would call API)
final newPlaylist = PlaylistModel(
id: DateTime.now().millisecondsSinceEpoch.toString(),
name: name,
description: '',
trackcount: 0,
isPublic: false,
createdDate: DateTime.now(),
lastModified: DateTime.now(),
);
setState(() {
_playlists.insert(0, newPlaylist);
});
_playlistNameController.clear();
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Playlist "$name" created successfully')),
);
}
String _formatDate(DateTime date) {
final now = DateTime.now();
final difference = now.difference(date);
if (difference.inDays == 0) {
return 'Today';
} else if (difference.inDays == 1) {
return 'Yesterday';
} else if (difference.inDays < 7) {
return '${difference.inDays} days ago';
} else if (difference.inDays < 30) {
return '${(difference.inDays / 7).floor()} weeks ago';
} else {
return '${(difference.inDays / 30).floor()} months ago';
}
}
}
@@ -1,292 +0,0 @@
import 'package:flutter/material.dart';
class QRScreen extends StatefulWidget {
const QRScreen({super.key});
@override
State<QRScreen> createState() => _QRScreenState();
}
class _QRScreenState extends State<QRScreen> {
String _qrCode = '';
bool _isGenerating = false;
bool _isScanning = false;
final TextEditingController _qrController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('QR Code Pairing'),
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
leading: IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.arrow_back),
),
),
body: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// QR Code Display
Container(
padding: const EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(16.0),
border: Border.all(
color: Theme.of(context).colorScheme.outline,
width: 2.0,
),
),
child: Column(
children: [
const Icon(
Icons.qr_code_scanner,
size: 80,
color: Colors.blue,
),
const SizedBox(height: 16),
Text(
'QR Code Pairing',
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
'Scan or generate a QR code to connect',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
// QR Code Visual
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12.0),
border: Border.all(
color: Theme.of(context).colorScheme.outline,
width: 2.0,
),
),
child: _isGenerating
? const Center(
child: CircularProgressIndicator(),
)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 180,
height: 180,
color: Colors.black,
child: const Center(
child: Text(
'QR CODE',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
),
),
const SizedBox(height: 16),
Text(
_qrCode.isEmpty ? 'Generate QR Code' : _qrCode,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
),
],
),
),
const SizedBox(height: 24),
// Action Buttons
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(
child: ElevatedButton(
onPressed: _isScanning ? null : _toggleScanning,
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.qr_code_scanner),
const SizedBox(width: 8),
const Text('Scan QR Code'),
],
),
),
),
const SizedBox(width: 16),
Expanded(
child: ElevatedButton(
onPressed: _isScanning ? null : _generateQRCode,
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.secondary,
foregroundColor: Theme.of(context).colorScheme.onSecondary,
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.qr_code),
const SizedBox(width: 8),
const Text('Generate QR'),
],
),
),
),
],
),
const SizedBox(height: 16),
// Manual Entry
TextField(
controller: _qrController,
decoration: InputDecoration(
labelText: 'Or enter QR code manually',
hintText: 'Enter QR code',
prefixIcon: const Icon(Icons.keyboard),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Theme.of(context).colorScheme.surfaceContainerHighest,
),
onChanged: (value) {
setState(() {
_qrCode = value;
});
},
),
const SizedBox(height: 24),
// Connect Button
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _qrCode.isEmpty ? null : _connectWithQR,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
),
child: const Text('Connect'),
),
),
],
),
),
],
),
),
);
}
void _toggleScanning() {
setState(() {
_isScanning = !_isScanning;
});
if (_isScanning) {
_scanQRCode();
}
}
void _generateQRCode() {
setState(() {
_isGenerating = true;
});
// Generate a random QR code for demo
Future.delayed(const Duration(seconds: 2)).then((_) {
setState(() {
_isGenerating = false;
_qrCode = 'SWING-${DateTime.now().millisecondsSinceEpoch % 10000}';
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('QR Code generated!')),
);
});
}
void _scanQRCode() async {
try {
// In a real app, this would use camera plugin
// For demo, we'll simulate scanning
await Future.delayed(const Duration(seconds: 3));
setState(() {
_isScanning = false;
_qrCode = 'DEMO-SCANNED-${DateTime.now().millisecondsSinceEpoch}';
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('QR Code scanned!')),
);
} catch (e) {
setState(() {
_isScanning = false;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Scan failed: ${e.toString()}')),
);
}
}
void _connectWithQR() async {
if (_qrCode.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Please enter or scan a QR code')),
);
return;
}
setState(() {
_isGenerating = true;
});
try {
// Simulate connection with QR code
await Future.delayed(const Duration(seconds: 2));
setState(() {
_isGenerating = false;
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Connected with QR Code!')),
);
// Navigate to main app
Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false);
} catch (e) {
setState(() {
_isGenerating = false;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Connection failed: ${e.toString()}')),
);
}
}
}
@@ -1,523 +0,0 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/audio_provider.dart';
import '../../core/widgets/album_card.dart';
import '../../core/widgets/track_list_tile.dart';
import '../../data/models/track_model.dart';
import '../../data/models/album_model.dart';
import '../../data/models/artist_model.dart' as artist_model;
import '../../data/models/search_suggestion_model.dart';
class SearchScreen extends StatefulWidget {
const SearchScreen({super.key});
@override
State<SearchScreen> createState() => _SearchScreenState();
}
class _SearchScreenState extends State<SearchScreen> with TickerProviderStateMixin {
late TabController _tabController;
final TextEditingController _searchController = TextEditingController();
final FocusNode _searchFocusNode = FocusNode();
// Search results
final List<TrackModel> _trackResults = [];
final List<AlbumModel> _albumResults = [];
final List<artist_model.ArtistModel> _artistResults = [];
bool _isSearching = false;
String _currentQuery = '';
// Search filters
String _selectedFilter = 'all'; // 'all', 'tracks', 'albums', 'artists'
final List<String> _searchFilters = ['all', 'tracks', 'albums', 'artists'];
@override
void initState() {
super.initState();
_tabController = TabController(length: 4, vsync: this);
_searchFocusNode.requestFocus();
}
@override
void dispose() {
_tabController.dispose();
_searchController.dispose();
_searchFocusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
// Search Header
Container(
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.1),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: Column(
children: [
// Search Bar
TextField(
controller: _searchController,
focusNode: _searchFocusNode,
onChanged: _onSearchChanged,
onSubmitted: _onSearchSubmitted,
decoration: InputDecoration(
hintText: 'Search tracks, albums, artists...',
prefixIcon: const Icon(Icons.search),
suffixIcon: _searchController.text.isNotEmpty
? IconButton(
onPressed: _clearSearch,
icon: const Icon(Icons.clear),
)
: null,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Theme.of(context).colorScheme.surfaceContainerHighest,
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
),
),
const SizedBox(height: 12),
// Filter Chips
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: _searchFilters.map((filter) {
final isSelected = _selectedFilter == filter;
return Padding(
padding: const EdgeInsets.only(right: 8),
child: FilterChip(
label: Text(filter.toUpperCase()),
selected: isSelected,
onSelected: (selected) {
setState(() {
_selectedFilter = filter;
});
_performSearch(_currentQuery);
},
backgroundColor: isSelected
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.surfaceContainerHighest,
labelStyle: TextStyle(
color: isSelected
? Theme.of(context).colorScheme.onPrimaryContainer
: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
);
}).toList(),
),
),
],
),
),
// Search Results
Expanded(
child: _isSearching
? const Center(child: CircularProgressIndicator())
: _currentQuery.isEmpty
? _buildSearchSuggestions()
: _buildSearchResults(),
),
],
),
);
}
Widget _buildSearchSuggestions() {
return DefaultTabController(
length: 4,
child: Column(
children: [
TabBar(
controller: _tabController,
isScrollable: true,
tabs: const [
Tab(text: 'Top'),
Tab(text: 'Tracks'),
Tab(text: 'Albums'),
Tab(text: 'Artists'),
],
),
Expanded(
child: TabBarView(
controller: _tabController,
children: [
_buildTopSearches(),
_buildRecentSearches(),
_buildBrowseGenres(),
_buildBrowseFolders(),
],
),
),
],
),
);
}
Widget _buildTopSearches() {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Top Searches',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
// Sample top searches
...['Rock', 'Pop', 'Jazz', 'Electronic', 'Classical'].map((genre) {
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: ListTile(
leading: Icon(
Icons.trending_up,
color: Theme.of(context).colorScheme.primary,
),
title: Text(genre),
trailing: const Icon(Icons.arrow_forward_ios),
onTap: () {
_searchController.text = genre;
_performSearch(genre);
},
),
);
}),
],
),
);
}
Widget _buildRecentSearches() {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Recent Searches',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
// Sample recent searches
...['Beatles', 'Queen', 'Pink Floyd', 'Led Zeppelin'].map((search) {
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: ListTile(
leading: Icon(
Icons.history,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
title: Text(search),
trailing: IconButton(
onPressed: () {
_searchController.text = search;
_performSearch(search);
},
icon: const Icon(Icons.arrow_forward_ios),
),
onTap: () {
_searchController.text = search;
_performSearch(search);
},
),
);
}),
],
),
);
}
Widget _buildBrowseGenres() {
return Padding(
padding: const EdgeInsets.all(16.0),
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 2.5,
crossAxisSpacing: 12,
mainAxisSpacing: 12,
),
itemCount: ['Rock', 'Pop', 'Jazz', 'Electronic', 'Classical', 'Hip Hop', 'Country', 'R&B'].length,
itemBuilder: (context, index) {
final genre = ['Rock', 'Pop', 'Jazz', 'Electronic', 'Classical', 'Hip Hop', 'Country', 'R&B'][index];
return Card(
child: InkWell(
onTap: () {
_searchController.text = genre;
_performSearch(genre);
},
borderRadius: BorderRadius.circular(8),
child: Center(
child: Text(
genre,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
fontWeight: FontWeight.w500,
),
),
),
),
);
},
),
);
}
Widget _buildBrowseFolders() {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.folder_outlined,
size: 64,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(height: 16),
Text(
'Folder browsing coming soon',
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
),
);
}
Widget _buildSearchResults() {
if (_selectedFilter == 'all') {
return DefaultTabController(
length: 3,
child: Column(
children: [
TabBar(
tabs: const [
Tab(text: 'Tracks'),
Tab(text: 'Albums'),
Tab(text: 'Artists'),
],
),
Expanded(
child: TabBarView(
children: [
_buildTrackResults(),
_buildAlbumResults(),
_buildArtistResults(),
],
),
),
],
),
);
} else if (_selectedFilter == 'tracks') {
return _buildTrackResults();
} else if (_selectedFilter == 'albums') {
return _buildAlbumResults();
} else {
return _buildArtistResults();
}
}
Widget _buildTrackResults() {
if (_trackResults.isEmpty) {
return _buildEmptyResults('No tracks found');
}
return ListView.builder(
itemCount: _trackResults.length,
itemBuilder: (context, index) {
final track = _trackResults[index];
return TrackListTile(
track: track,
onTap: () => _playTrack(track),
onPlay: () => _playTrack(track),
);
},
);
}
Widget _buildAlbumResults() {
if (_albumResults.isEmpty) {
return _buildEmptyResults('No albums found');
}
return GridView.builder(
padding: const EdgeInsets.all(16.0),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.8,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
itemCount: _albumResults.length,
itemBuilder: (context, index) {
final album = _albumResults[index];
return AlbumCard(
album: album,
onTap: () {
// Navigate to album details
},
);
},
);
}
Widget _buildArtistResults() {
if (_artistResults.isEmpty) {
return _buildEmptyResults('No artists found');
}
return ListView.builder(
itemCount: _artistResults.length,
itemBuilder: (context, index) {
final artist = _artistResults[index];
return ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
child: Text(
artist.name.isNotEmpty ? artist.name[0].toUpperCase() : '?',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer,
fontWeight: FontWeight.bold,
),
),
),
title: Text(artist.name),
trailing: const Icon(Icons.arrow_forward_ios),
onTap: () {
// Navigate to artist details
},
);
},
);
}
Widget _buildEmptyResults(String message) {
return Center(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.search_off,
size: 64,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(height: 16),
Text(
message,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 8),
Text(
'Try different keywords or browse categories',
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
],
),
),
);
}
void _onSearchChanged(String query) {
_currentQuery = query;
if (query.isEmpty) {
setState(() {
_isSearching = false;
_trackResults.clear();
_albumResults.clear();
_artistResults.clear();
});
} else {
// Debounce search
Future.delayed(const Duration(milliseconds: 500), () {
if (_searchController.text == query) {
_performSearch(query);
}
});
}
}
void _onSearchSubmitted(String query) {
_performSearch(query);
_searchFocusNode.unfocus();
}
void _clearSearch() {
_searchController.clear();
setState(() {
_currentQuery = '';
_isSearching = false;
_trackResults.clear();
_albumResults.clear();
_artistResults.clear();
});
}
Future<void> _performSearch(String query) async {
if (query.trim().isEmpty) return;
setState(() {
_isSearching = true;
});
try {
// Simulate API call
await Future.delayed(const Duration(milliseconds: 800));
// This would be actual API calls
setState(() {
_isSearching = false;
// For demo, just clear results
_trackResults.clear();
_albumResults.clear();
_artistResults.clear();
});
} catch (e) {
setState(() {
_isSearching = false;
});
// Handle error
}
}
void _playTrack(TrackModel track) {
final audioProvider = Provider.of<AudioProvider>(context, listen: false);
audioProvider.setQueue([track]);
audioProvider.loadTrack(track);
audioProvider.play();
Navigator.pushNamed(context, '/player');
}
}
@@ -1,845 +0,0 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/auth_provider.dart';
import '../../shared/providers/enhanced_library_provider.dart';
import '../../core/constants/app_spacing.dart';
class EnhancedSettingsScreen extends StatefulWidget {
const EnhancedSettingsScreen({super.key});
@override
State<EnhancedSettingsScreen> createState() => _EnhancedSettingsScreenState();
}
class _EnhancedSettingsScreenState extends State<EnhancedSettingsScreen> {
bool _isExpanded = false;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.surface,
elevation: 0,
title: Text(
'Settings',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.w600,
),
),
leading: IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: Icon(
Icons.arrow_back,
color: Theme.of(context).colorScheme.onSurface,
),
),
),
body: SingleChildScrollView(
padding: AppSpacing.paddingLG,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Connection Settings
_buildSection(
context,
'Connection',
Icons.cloud,
[
_buildServerUrlTile(context),
_buildAuthStatusTile(context),
_buildConnectionTestTile(context),
],
),
const SizedBox(height: 24),
// Audio Settings
_buildSection(
context,
'Audio',
Icons.music_note,
[
_buildAudioQualityTile(context),
_buildCrossfadeTile(context),
_buildGaplessTile(context),
_buildVolumeTile(context),
],
),
const SizedBox(height: 24),
// Download Settings
_buildSection(
context,
'Downloads',
Icons.download,
[
_buildDownloadQualityTile(context),
_buildDownloadLocationTile(context),
_buildWifiOnlyTile(context),
_buildMaxDownloadSizeTile(context),
],
),
const SizedBox(height: 24),
// Theme Settings
_buildSection(
context,
'Appearance',
Icons.palette,
[
_buildThemeTile(context),
_buildAccentColorTile(context),
],
),
const SizedBox(height: 24),
// Cache Settings
_buildSection(
context,
'Storage',
Icons.storage,
[
_buildCacheSizeTile(context),
_buildClearCacheTile(context),
],
),
const SizedBox(height: 24),
// About
_buildSection(
context,
'About',
Icons.info,
[
_buildVersionTile(context),
_buildBuildNumberTile(context),
_buildDeveloperTile(context),
],
),
],
),
),
);
}
Widget _buildSection(
BuildContext context,
String title,
IconData icon,
List<Widget> children,
) {
return Container(
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant,
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Icon(
icon,
color: Theme.of(context).colorScheme.primary,
size: 20,
),
const SizedBox(width: 12),
Text(
title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
),
...children,
],
),
);
}
Widget _buildServerUrlTile(BuildContext context) {
return Consumer<AuthProvider>(
builder: (context, authProvider, child) {
return ListTile(
leading: Icon(
Icons.link,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Server URL',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
authProvider.baseUrl ?? 'Not set',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: IconButton(
onPressed: () => _showServerUrlDialog(context, authProvider),
icon: Icon(
Icons.edit,
color: Theme.of(context).colorScheme.primary,
),
),
);
},
);
}
Widget _buildAuthStatusTile(BuildContext context) {
return Consumer<AuthProvider>(
builder: (context, authProvider, child) {
return ListTile(
leading: Icon(
authProvider.isLoggedIn ? Icons.check_circle : Icons.error,
color: authProvider.isLoggedIn
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.error,
),
title: Text(
'Authentication Status',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
authProvider.isLoggedIn ? 'Connected' : 'Not connected',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: authProvider.isLoggedIn
? Theme.of(context).colorScheme.onSurface.withOpacity(0.7)
: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: authProvider.isLoggedIn
? IconButton(
onPressed: () => _showLogoutDialog(context, authProvider),
icon: Icon(
Icons.logout,
color: Theme.of(context).colorScheme.error,
),
)
: null,
);
},
);
}
Widget _buildConnectionTestTile(BuildContext context) {
return ListTile(
leading: Icon(
Icons.wifi,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Test Connection',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Check server connectivity',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: IconButton(
onPressed: () => _testConnection(context),
icon: Icon(
Icons.play_arrow,
color: Theme.of(context).colorScheme.primary,
),
),
);
}
Widget _buildAudioQualityTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.high_quality,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Audio Quality',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Higher quality uses more storage',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['audioQuality'] ?? '320kbps',
items: const ['128kbps', '320kbps', '512kbps', 'flac'],
onChanged: (value) => libraryProvider.updateUserPreferences({
'audioQuality': value,
}),
),
);
},
);
}
Widget _buildCrossfadeTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.blur_on,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Crossfade',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Smooth transitions between tracks',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: Switch(
value: libraryProvider.userPreferences['crossfade'] ?? false,
onChanged: (value) => libraryProvider.updateUserPreferences({
'crossfade': value,
}),
),
);
},
);
}
Widget _buildGaplessTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.skip_next,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Gapless Playback',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Remove silence between tracks',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: Switch(
value: libraryProvider.userPreferences['gapless'] ?? false,
onChanged: (value) => libraryProvider.updateUserPreferences({
'gapless': value,
}),
),
);
},
);
}
Widget _buildVolumeTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.volume_up,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Default Volume',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Set default volume level',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<double>(
value: (libraryProvider.userPreferences['defaultVolume'] ?? 1.0).toDouble(),
items: [0.25, 0.5, 0.75, 1.0],
onChanged: (value) => libraryProvider.updateUserPreferences({
'defaultVolume': value,
}),
),
);
},
);
}
Widget _buildDownloadQualityTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.download,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Download Quality',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Choose audio quality for downloads',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['downloadQuality'] ?? '320kbps',
items: const ['128kbps', '320kbps', '512kbps', 'flac'],
onChanged: (value) => libraryProvider.updateUserPreferences({
'downloadQuality': value,
}),
),
);
},
);
}
Widget _buildDownloadLocationTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.folder,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Download Location',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Where to save downloaded files',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['downloadLocation'] ?? 'Music',
items: const ['Music', 'Downloads', 'Custom'],
onChanged: (value) => libraryProvider.updateUserPreferences({
'downloadLocation': value,
}),
),
);
},
);
}
Widget _buildWifiOnlyTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.wifi,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Wi-Fi Only',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Download only when connected to Wi-Fi',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: Switch(
value: libraryProvider.userPreferences['wifiOnly'] ?? false,
onChanged: (value) => libraryProvider.updateUserPreferences({
'wifiOnly': value,
}),
),
);
},
);
}
Widget _buildMaxDownloadSizeTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.sd_storage,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Max Download Size',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Maximum size for automatic downloads',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['maxDownloadSize'] ?? '100MB',
items: const ['50MB', '100MB', '500MB', '1GB'],
onChanged: (value) => libraryProvider.updateUserPreferences({
'maxDownloadSize': value,
}),
),
);
},
);
}
Widget _buildThemeTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.palette,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Theme',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Choose app appearance',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<ThemeMode>(
value: _getThemeMode(libraryProvider.userPreferences['theme']),
items: const [
DropdownMenuItem(value: ThemeMode.system, child: Text('System')),
DropdownMenuItem(value: ThemeMode.light, child: Text('Light')),
DropdownMenuItem(value: ThemeMode.dark, child: Text('Dark')),
],
onChanged: (ThemeMode? value) => libraryProvider.updateUserPreferences({
'theme': value?.name,
}),
),
);
},
);
}
Widget _buildAccentColorTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.color_lens,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Accent Color',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Customize accent colors',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['accentColor'] ?? 'Blue',
items: const [
DropdownMenuItem(value: 'Blue', child: Text('Blue')),
DropdownMenuItem(value: 'Green', child: Text('Green')),
DropdownMenuItem(value: 'Purple', child: Text('Purple')),
DropdownMenuItem(value: 'Orange', child: Text('Orange')),
DropdownMenuItem(value: 'Red', child: Text('Red')),
],
onChanged: (String? value) => libraryProvider.updateUserPreferences({
'accentColor': value,
}),
),
);
},
);
}
Widget _buildCacheSizeTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.cached,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Cache Size',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Maximum cache size',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['cacheSize'] ?? '500MB',
items: const ['100MB', '500MB', '1GB', '2GB', '5GB'],
onChanged: (String? value) => libraryProvider.updateUserPreferences({
'cacheSize': value,
}),
),
);
},
);
}
Widget _buildClearCacheTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.clear_all,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Clear Cache',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Free up storage space',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: IconButton(
onPressed: () => _showClearCacheDialog(context),
icon: Icon(
Icons.delete_sweep,
color: Theme.of(context).colorScheme.error,
),
),
);
},
);
}
Widget _buildVersionTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.info,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Version',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
libraryProvider.statistics['version'] ?? 'Unknown',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
);
},
);
}
Widget _buildBuildNumberTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.build,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Build Number',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
libraryProvider.statistics['buildNumber'] ?? 'Unknown',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
);
},
);
}
Widget _buildDeveloperTile(BuildContext context) {
return ListTile(
leading: Icon(
Icons.code,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Developer',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'View developer options',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
trailing: IconButton(
onPressed: () => _showDeveloperOptions(context),
icon: Icon(
Icons.more_horiz,
color: Theme.of(context).colorScheme.primary,
),
),
);
}
ThemeMode _getThemeMode(String? themeString) {
switch (themeString) {
case 'system':
return ThemeMode.system;
case 'light':
return ThemeMode.light;
case 'dark':
return ThemeMode.dark;
default:
return ThemeMode.system;
}
}
void _showServerUrlDialog(BuildContext context, AuthProvider authProvider) {
final controller = TextEditingController(text: authProvider.baseUrl ?? '');
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Server URL'),
content: TextField(
controller: controller,
decoration: InputDecoration(
labelText: 'Server URL',
hintText: 'https://your-server.com',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.outline,
),
),
),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'),
),
TextButton(
onPressed: () {
authProvider.updateBaseUrl(controller.text.trim());
Navigator.of(context).pop();
},
child: Text('Save'),
),
],
),
);
}
void _showLogoutDialog(BuildContext context, AuthProvider authProvider) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Logout'),
content: Text('Are you sure you want to logout?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'),
),
TextButton(
onPressed: () {
authProvider.logout();
Navigator.of(context).pop();
},
child: Text('Logout'),
),
],
),
);
}
void _testConnection(BuildContext context) {
// TODO: Implement connection test
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Connection test not implemented yet')),
);
}
void _showClearCacheDialog(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Clear Cache'),
content: Text('Are you sure you want to clear all cached data?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Cache cleared successfully')),
);
},
child: Text('Clear'),
),
],
),
);
}
void _showDeveloperOptions(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Developer Options'),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListTile(
title: Text('Debug Mode'),
trailing: Switch(
value: false,
onChanged: (value) {
// TODO: Implement debug mode
},
),
),
ListTile(
title: Text('Enable Logging'),
trailing: Switch(
value: false,
onChanged: (value) {
// TODO: Implement logging
},
),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Close'),
),
],
),
);
}
}
@@ -1,518 +0,0 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../core/constants/app_constants.dart';
class SettingsScreen extends StatefulWidget {
const SettingsScreen({super.key});
@override
State<SettingsScreen> createState() => _SettingsScreenState();
}
class _SettingsScreenState extends State<SettingsScreen> {
bool _isLoading = false;
// Connection settings
String _serverUrl = '';
String _username = '';
bool _isConnected = false;
// Audio settings
double _volume = 1.0;
double _audioQuality = 1.0; // 0.5 = Low, 1.0 = High
bool _gaplessPlayback = false;
bool _crossfade = true;
double _crossfadeDuration = 5.0;
// Theme settings
ThemeMode _themeMode = ThemeMode.system;
// Download settings
String _downloadQuality = 'high'; // 'low', 'medium', 'high'
bool _wifiOnlyDownloads = true;
int _maxDownloadSize = 1000; // MB
// Cache settings
int _cacheSize = 500; // MB
bool _clearCacheOnStart = false;
// Analytics settings
bool _enableAnalytics = true;
bool _shareListeningData = false;
@override
void initState() {
super.initState();
_loadSettings();
}
Future<void> _loadSettings() async {
setState(() {
_isLoading = true;
});
final prefs = await SharedPreferences.getInstance();
setState(() {
_serverUrl = prefs.getString('server_url') ?? AppConstants.defaultApiUrl;
_username = prefs.getString('username') ?? '';
_isConnected = prefs.getBool('is_connected') ?? false;
_volume = prefs.getDouble('volume') ?? 1.0;
_audioQuality = prefs.getDouble('audio_quality') ?? 1.0;
_gaplessPlayback = prefs.getBool('gapless_playback') ?? false;
_crossfade = prefs.getBool('crossfade') ?? true;
_crossfadeDuration = prefs.getDouble('crossfade_duration') ?? 5.0;
final themeIndex = prefs.getInt('theme_mode') ?? 2;
_themeMode = ThemeMode.values[themeIndex];
_downloadQuality = prefs.getString('download_quality') ?? 'high';
_wifiOnlyDownloads = prefs.getBool('wifi_only_downloads') ?? true;
_maxDownloadSize = prefs.getInt('max_download_size') ?? 1000;
_cacheSize = prefs.getInt('cache_size') ?? 500;
_clearCacheOnStart = prefs.getBool('clear_cache_on_start') ?? false;
_enableAnalytics = prefs.getBool('enable_analytics') ?? true;
_shareListeningData = prefs.getBool('share_listening_data') ?? false;
_isLoading = false;
});
}
Future<void> _saveSettings() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('server_url', _serverUrl);
await prefs.setString('username', _username);
await prefs.setBool('is_connected', _isConnected);
await prefs.setDouble('volume', _volume);
await prefs.setDouble('audio_quality', _audioQuality);
await prefs.setBool('gapless_playback', _gaplessPlayback);
await prefs.setBool('crossfade', _crossfade);
await prefs.setDouble('crossfade_duration', _crossfadeDuration);
await prefs.setInt('theme_mode', _themeMode.index);
await prefs.setString('download_quality', _downloadQuality);
await prefs.setBool('wifi_only_downloads', _wifiOnlyDownloads);
await prefs.setInt('max_download_size', _maxDownloadSize);
await prefs.setInt('cache_size', _cacheSize);
await prefs.setBool('clear_cache_on_start', _clearCacheOnStart);
await prefs.setBool('enable_analytics', _enableAnalytics);
await prefs.setBool('share_listening_data', _shareListeningData);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Settings'),
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
actions: [
TextButton(
onPressed: _saveSettings,
child: const Text('Save'),
),
],
),
body: _isLoading
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(16.0),
children: [
// Connection Section
_buildSectionHeader('Connection'),
_buildServerUrlField(),
_buildUsernameField(),
_buildConnectionStatus(),
const SizedBox(height: 24),
// Audio Section
_buildSectionHeader('Audio'),
_buildVolumeSlider(),
_buildAudioQualityDropdown(),
_buildGaplessPlaybackSwitch(),
_buildCrossfadeSwitch(),
_buildCrossfadeDurationSlider(),
const SizedBox(height: 24),
// Theme Section
_buildSectionHeader('Appearance'),
_buildThemeSelector(),
const SizedBox(height: 24),
// Download Section
_buildSectionHeader('Downloads'),
_buildDownloadQualityDropdown(),
_buildWifiOnlySwitch(),
_buildMaxDownloadSizeField(),
const SizedBox(height: 24),
// Cache Section
_buildSectionHeader('Storage'),
_buildCacheSizeField(),
_buildClearCacheSwitch(),
_buildClearCacheButton(),
const SizedBox(height: 24),
// Analytics Section
_buildSectionHeader('Analytics'),
_buildAnalyticsSwitch(),
_buildShareDataSwitch(),
const SizedBox(height: 24),
// About Section
_buildSectionHeader('About'),
_buildAppInfo(),
_buildVersionInfo(),
],
),
);
}
Widget _buildSectionHeader(String title) {
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Text(
title,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
);
}
Widget _buildServerUrlField() {
return TextField(
controller: TextEditingController(text: _serverUrl),
decoration: const InputDecoration(
labelText: 'Server URL',
hintText: 'http://192.168.1.100:1970',
border: OutlineInputBorder(),
),
onChanged: (value) {
_serverUrl = value;
},
);
}
Widget _buildUsernameField() {
return TextField(
controller: TextEditingController(text: _username),
decoration: const InputDecoration(
labelText: 'Username',
border: OutlineInputBorder(),
),
onChanged: (value) {
_username = value;
},
);
}
Widget _buildConnectionStatus() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: _isConnected ? Colors.green : Colors.red,
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Icon(
_isConnected ? Icons.check_circle : Icons.error,
color: Colors.white,
),
const SizedBox(width: 8),
Text(
_isConnected ? 'Connected' : 'Disconnected',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
],
),
);
}
Widget _buildVolumeSlider() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Volume: ${(_volume * 100).round()}%'),
Slider(
value: _volume,
min: 0.0,
max: 1.0,
divisions: 20,
onChanged: (value) {
setState(() {
_volume = value;
});
},
),
],
);
}
Widget _buildAudioQualityDropdown() {
return DropdownButtonFormField<String>(
decoration: const InputDecoration(
labelText: 'Audio Quality',
border: OutlineInputBorder(),
),
items: ['Low', 'Medium', 'High'].map((quality) {
return DropdownMenuItem(
value: quality,
child: Text(quality),
);
}).toList(),
onChanged: (value) {
if (value != null) {
setState(() {
_audioQuality = value == 'Low' ? 0.5 : value == 'High' ? 1.0 : 0.75;
});
}
},
);
}
Widget _buildGaplessPlaybackSwitch() {
return SwitchListTile(
title: const Text('Gapless Playback'),
subtitle: const Text('Remove gaps between tracks'),
value: _gaplessPlayback,
onChanged: (value) {
setState(() {
_gaplessPlayback = value;
});
},
);
}
Widget _buildCrossfadeSwitch() {
return SwitchListTile(
title: const Text('Crossfade'),
subtitle: const Text('Smooth transition between tracks'),
value: _crossfade,
onChanged: (value) {
setState(() {
_crossfade = value;
});
},
);
}
Widget _buildCrossfadeDurationSlider() {
if (!_crossfade) return const SizedBox.shrink();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Crossfade Duration: ${_crossfadeDuration.round()}s'),
Slider(
value: _crossfadeDuration,
min: 1.0,
max: 10.0,
divisions: 18,
onChanged: (value) {
setState(() {
_crossfadeDuration = value;
});
},
),
],
);
}
Widget _buildThemeSelector() {
return Column(
children: [
RadioListTile<ThemeMode>(
title: const Text('Light'),
value: ThemeMode.light,
groupValue: _themeMode,
onChanged: (ThemeMode? value) {
if (value != null) {
setState(() {
_themeMode = value;
});
}
},
),
RadioListTile<ThemeMode>(
title: const Text('Dark'),
value: ThemeMode.dark,
groupValue: _themeMode,
onChanged: (ThemeMode? value) {
if (value != null) {
setState(() {
_themeMode = value;
});
}
},
),
RadioListTile<ThemeMode>(
title: const Text('System'),
value: ThemeMode.system,
groupValue: _themeMode,
onChanged: (ThemeMode? value) {
if (value != null) {
setState(() {
_themeMode = value;
});
}
},
),
],
);
}
Widget _buildDownloadQualityDropdown() {
return DropdownButtonFormField<String>(
decoration: const InputDecoration(
labelText: 'Download Quality',
border: OutlineInputBorder(),
),
items: ['Low', 'Medium', 'High'].map((quality) {
return DropdownMenuItem(
value: quality,
child: Text(quality),
);
}).toList(),
onChanged: (value) {
if (value != null) {
setState(() {
_downloadQuality = value;
});
}
},
);
}
Widget _buildWifiOnlySwitch() {
return SwitchListTile(
title: const Text('Wi-Fi Only Downloads'),
subtitle: const Text('Only download when connected to Wi-Fi'),
value: _wifiOnlyDownloads,
onChanged: (value) {
setState(() {
_wifiOnlyDownloads = value;
});
},
);
}
Widget _buildMaxDownloadSizeField() {
return TextField(
controller: TextEditingController(text: _maxDownloadSize.toString()),
decoration: const InputDecoration(
labelText: 'Max Download Size (MB)',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
onChanged: (value) {
_maxDownloadSize = int.tryParse(value) ?? _maxDownloadSize;
},
);
}
Widget _buildCacheSizeField() {
return TextField(
controller: TextEditingController(text: _cacheSize.toString()),
decoration: const InputDecoration(
labelText: 'Cache Size (MB)',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
onChanged: (value) {
_cacheSize = int.tryParse(value) ?? _cacheSize;
},
);
}
Widget _buildClearCacheSwitch() {
return SwitchListTile(
title: const Text('Clear Cache on Start'),
subtitle: const Text('Clear cache when app starts'),
value: _clearCacheOnStart,
onChanged: (value) {
setState(() {
_clearCacheOnStart = value;
});
},
);
}
Widget _buildClearCacheButton() {
return ElevatedButton.icon(
onPressed: () async {
// Clear cache logic
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Cache cleared')),
);
},
icon: const Icon(Icons.delete_outline),
label: const Text('Clear Cache'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
);
}
Widget _buildAnalyticsSwitch() {
return SwitchListTile(
title: const Text('Enable Analytics'),
subtitle: const Text('Track listening statistics'),
value: _enableAnalytics,
onChanged: (value) {
setState(() {
_enableAnalytics = value;
});
},
);
}
Widget _buildShareDataSwitch() {
return SwitchListTile(
title: const Text('Share Listening Data'),
subtitle: const Text('Share anonymous listening data for improvements'),
value: _shareListeningData,
onChanged: (value) {
setState(() {
_shareListeningData = value;
});
},
);
}
Widget _buildAppInfo() {
return ListTile(
leading: const Icon(Icons.info_outline),
title: const Text('About SwingMusic'),
trailing: const Icon(Icons.arrow_forward_ios),
onTap: () {
showAboutDialog(
context: context,
applicationName: 'SwingMusic',
applicationVersion: '1.0.0',
applicationIcon: const Icon(Icons.music_note),
children: [
const Text('A modern music player for SwingMusic server'),
const Text('Built with Flutter'),
],
);
},
);
}
Widget _buildVersionInfo() {
return ListTile(
leading: const Icon(Icons.code),
title: const Text('Version'),
subtitle: const Text('1.0.0 (Flutter)'),
trailing: const Icon(Icons.arrow_forward_ios),
onTap: () {
// Show changelog
},
);
}
}