This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| runApp(MusicPlayerApp()); | |
| } | |
| class MusicPlayerApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return ProviderScope( | |
| child: MaterialApp( | |
| title: 'Music Player', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final playlistProvider = Provider((ref) => [ | |
| AudioTrackModel( | |
| artistName: 'Benjamin Tissot', | |
| trackName: 'My Old East Coast (feat. Melanie)', | |
| thumbnail: 'https://www.bensound.com/bensound-img/ukulele.jpg', | |
| audioUrl: | |
| 'https://www.bensound.com/bensound-music/bensound-ukulele.mp3'), | |
| AudioTrackModel( | |
| artistName: 'Benjamin Tissot', | |
| trackName: 'Creative Minds', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AudioTrackModel { | |
| final artistName; | |
| final trackName; | |
| final audioUrl; | |
| final thumbnail; | |
| AudioTrackModel( | |
| {this.artistName, this.trackName, this.audioUrl, this.thumbnail}); | |
| bool get isEmpty => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dependencies: | |
| flutter: | |
| sdk: flutter | |
| flutter_riverpod: ^0.10.1 | |
| state_notifier: ^0.6.0 | |
| assets_audio_player: ^2.0.10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PlayerControlWidget extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Column( | |
| children: [ | |
| Row( | |
| mainAxisSize: MainAxisSize.max, | |
| children: [ | |
| Text('0:00'), | |
| Flexible( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AudioTrackTile extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return ListTile( | |
| leading: Image.network( | |
| audioTrack.thumbnail, | |
| height: 60, | |
| width: 60, | |
| fit: BoxFit.cover, | |
| ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final audioPlayerProvider = Provider.autoDispose<AssetsAudioPlayer>((ref) { | |
| final playlist = ref.watch(playlistProvider); | |
| final audioPlayer = AssetsAudioPlayer(); | |
| audioPlayer.open( | |
| Playlist( | |
| audios: playlist | |
| .map((audioTrackModel) => Audio.network(audioTrackModel.audioUrl)) | |
| .toList()), | |
| autoStart: false); | |
| return audioPlayer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:mobx/mobx.dart'; | |
| extension MobxObjectExtension<T> on T { | |
| // e.g : instead of using var element = Observable(0); | var element = 0.obs; | |
| Observable get obs => Observable<T>(this); | |
| // e.g : instead of using var element = ObservableFuture.value(0) | var element = 0.fObsValue; | |
| ObservableFuture get fObsValue => ObservableFuture<T>.value(this); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:mobx/mobx.dart'; | |
| // Dart Extensions | |
| extension MobxObjectExtension on Object { | |
| Observable get obs => Observable(this); | |
| } | |
| extension MobxFunctionExtension on Function { | |
| Action get action => Action(this); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:mobx/mobx.dart'; | |
| // Dart Extensions | |
| extension MobxObjectExtension on Object { | |
| Observable get obs => Observable(this); | |
| } | |
| extension MobxFunctionExtension on Function { | |
| Action get action => Action(this); | |
| } |