import 'package:fipy/providers/home.dart'; import 'package:fipy/providers/player.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class PlayerControls extends StatelessWidget { const PlayerControls({ Key? key, }) : super(key: key); @override Widget build(BuildContext context) { final hp = Provider.of(context, listen: true); final playerProvider = Provider.of(context, listen: true); return Column(children: [ const Spacer(), Row(children: [ const SizedBox(width: 70), Column(children: [ IconButton( padding: const EdgeInsets.all(0), icon: Icon(Icons.skip_previous, color: Colors.grey[500], size: 32), onPressed: () { hp.backTrack(); }), ]), const SizedBox(width: 1), ElevatedButton( onPressed: () { hp.resumePlay(); }, style: ElevatedButton.styleFrom( foregroundColor: Colors.grey[900], backgroundColor: Colors.grey[300], shape: const CircleBorder(), padding: const EdgeInsets.all(12), ), child: Icon( hp.player.state.name == 'playing' ? Icons.pause : Icons.play_arrow, color: Colors.grey[900], size: 30), ), Column(children: [ IconButton( padding: const EdgeInsets.all(0), icon: Icon(Icons.skip_next, color: Colors.grey[500], size: 32), onPressed: () { hp.nextTrack(); }), // const SizedBox(height: 7), ]), ]), const Spacer(), Row(children: [ const SizedBox(width: 70), Text( timeFormat(hp.currentTrack?.position ?? const Duration(seconds: 0)), style: TextStyle(color: Colors.grey[500], fontSize: 12), ), const SizedBox(width: 3), (hp.currentTrack?.duration?.inSeconds ?? -1) <= 0 ? Column( children: [ const SizedBox(width: 300), hp.currentTrack?.title == null ? Text( 'Choisissez un titre', style: TextStyle(color: Colors.grey[500]), ) : const SizedBox( height: 15, width: 15, child: CircularProgressIndicator( strokeWidth: 2, color: Colors.orange, ), ), ], ) : SliderTheme( data: const SliderThemeData( thumbShape: RoundSliderThumbShape(enabledThumbRadius: 2), overlayShape: RoundSliderThumbShape(enabledThumbRadius: 5), trackHeight: 2, ), child: SizedBox( width: 300, child: Slider( value: double.parse( hp.currentTrack?.position?.inSeconds.toString() ?? '0'), max: double.parse( hp.currentTrack?.duration?.inSeconds.toString() ?? '2000'), onChanged: (double value) { if (hp.currentTrack?.position != null) { hp.player.seek( Duration(seconds: value.toInt()), ); playerProvider.reload(); } }, activeColor: Colors.grey[400], inactiveColor: Colors.grey[700], ), ), ), const SizedBox(width: 3), Text( timeFormat(hp.currentTrack?.duration ?? const Duration(seconds: 0)), style: TextStyle(color: Colors.grey[500], fontSize: 12), ), ]), const Spacer(), ]); } } String timeFormat(Duration d) { String dd = d.toString().split('.').first; String minutes = dd.toString().split(':')[1]; String seconds = dd.toString().split(':')[2]; return '$minutes:$seconds'; }