diff --git a/lib/provider/player_provider.dart b/lib/provider/player_provider.dart index ea337b1..0de5953 100644 --- a/lib/provider/player_provider.dart +++ b/lib/provider/player_provider.dart @@ -3,28 +3,19 @@ import 'package:flutter/material.dart'; enum PlayerState { stopped, playing, paused } -var audioManagerInstance = AudioManager.instance; - -bool isPlaying = audioManagerInstance.isPlaying; -double slider = 0.0; - class PlayerProvider extends ChangeNotifier { Duration duration; Duration position; - - PlayerState playerState = PlayerState.stopped; + PlayerState playerState; + double slider = 0.0; + var audioManagerInstance = AudioManager.instance; get isPlaying => playerState == PlayerState.playing; get isPaused => playerState == PlayerState.paused; - get durationText => - duration != null ? duration.toString().split('.').first : ''; - - get positionText => - position != null ? position.toString().split('.').first : ''; - void setUpAudio() { + playerState = PlayerState.stopped; audioManagerInstance.onEvents((events, args) { switch (events) { case AudioManagerEvents.start: diff --git a/lib/provider/song_widget.dart b/lib/provider/song_widget.dart index 0e68897..068c31d 100644 --- a/lib/provider/song_widget.dart +++ b/lib/provider/song_widget.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:fluttertoast/fluttertoast.dart'; +import 'package:provider/provider.dart'; import 'package:raag/model/music_model.dart'; import 'package:raag/provider/player_provider.dart'; import 'package:raag/view/playback_controls.dart'; @@ -32,6 +32,7 @@ class _SongWidgetState extends State with TickerProviderStateMixin { @override Widget build(BuildContext context) { final screenWidth = MediaQuery.of(context).size.width; + final provider = Provider.of(context); return Stack( children: [ @@ -54,41 +55,12 @@ class _SongWidgetState extends State with TickerProviderStateMixin { color: Colors.transparent, child: ListTile( contentPadding: EdgeInsets.zero, - trailing: Row( - mainAxisSize: MainAxisSize.min, - children: [ - IconButton( - icon: Icon( - Icons.more_vert, - size: 20.0, - color: Theme.of(context).accentColor, - ), - onPressed: () { - Fluttertoast.showToast( - msg: 'Feature yet to be released'); - showMenu( - context: context, - position: RelativeRect.fromLTRB(100, 100, 0, - 100), //TODO Should not be constant - items: [ - PopupMenuItem( - child: const Text('Like'), - value: 'Doge'), - PopupMenuItem( - child: const Text('Add to Playlist'), - value: 'Lion'), - PopupMenuItem( - child: const Text('Song info'), - value: 'Lion'), - ]); - }, - ) - ], - ), title: InkWell( onTap: () { - if(audioManagerInstance.isPlaying) audioManagerInstance.toPause(); - audioManagerInstance + if (provider.audioManagerInstance.isPlaying) + provider.audioManagerInstance.toPause(); + provider.playerState = PlayerState.playing; + provider.audioManagerInstance .start("file://${song.filePath}", song.title, desc: song.displayName, auto: true, @@ -106,16 +78,20 @@ class _SongWidgetState extends State with TickerProviderStateMixin { ), SizedBox(width: screenWidth * 0.03,), Container( - width: MediaQuery.of(context).size.width * 0.6, + width: MediaQuery + .of(context) + .size + .width * 0.7, child: Column( mainAxisAlignment: - MainAxisAlignment.spaceEvenly, + MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text(song.title, overflow: TextOverflow.ellipsis, - style: Theme.of(context) + style: Theme + .of(context) .textTheme .headline3), Text(song.artist, @@ -143,7 +119,11 @@ class _SongWidgetState extends State with TickerProviderStateMixin { height: 0, ); }), - PlayBackControls() + PlayBackControls(), + SizedBox(height: MediaQuery + .of(context) + .size + .height * 0.2,) ], ); } diff --git a/lib/view/playback_controls.dart b/lib/view/playback_controls.dart index 6a345fd..397a236 100644 --- a/lib/view/playback_controls.dart +++ b/lib/view/playback_controls.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import 'package:raag/provider/audio_helper.dart'; import 'package:raag/provider/player_provider.dart'; import 'package:raag/widgets/seekbar.dart'; @@ -11,11 +12,19 @@ class PlayBackControls extends StatefulWidget { class _PlayBackControlsState extends State { @override Widget build(BuildContext context) { + var glowShadow = BoxShadow( + color: Theme.of(context).accentColor.withOpacity(0.3), + spreadRadius: 3, + blurRadius: 9, + offset: Offset(0, 0), // changes position of shadow + ); + final provider = Provider.of(context); return Column( mainAxisAlignment: MainAxisAlignment.end, children: [ Container( decoration: BoxDecoration( + boxShadow: [glowShadow], color: Theme.of(context).backgroundColor, borderRadius: BorderRadius.only( topRight: Radius.circular(20), @@ -57,7 +66,7 @@ class _PlayBackControlsState extends State { ), elevation: 0, onPressed: () { - audioManagerInstance.previous(); + provider.audioManagerInstance.previous(); }), ), ), @@ -85,10 +94,15 @@ class _PlayBackControlsState extends State { ), elevation: 0, onPressed: () { - audioManagerInstance.isPlaying - ? playFABController.reverse() - : playFABController.forward(); - audioManagerInstance.playOrPause(); + if (provider.audioManagerInstance.isPlaying) { + playFABController.reverse(); + provider.playerState = PlayerState.paused; + } + else { + playFABController.forward(); + provider.playerState = PlayerState.playing; + } + provider.audioManagerInstance.playOrPause(); }), ), ), @@ -115,7 +129,7 @@ class _PlayBackControlsState extends State { ), elevation: 0, onPressed: () { - audioManagerInstance.next(); + provider.audioManagerInstance.next(); }), ), ), @@ -134,17 +148,17 @@ class _PlayBackControlsState extends State { ), child: new Center( child: RawMaterialButton( - shape: CircleBorder(), - onPressed: () { - audioManagerInstance.stop(); - playFABController.reverse(); - }, - child: Icon( - Icons.stop, - color: Theme.of(context).accentColor, - ), - elevation: 4, - )), + shape: CircleBorder(), + onPressed: () { + provider.audioManagerInstance.stop(); + playFABController.reverse(); + }, + child: Icon( + Icons.stop, + color: Theme.of(context).accentColor, + ), + elevation: 4, + )), ), ], ), diff --git a/lib/widgets/seekbar.dart b/lib/widgets/seekbar.dart index eb2e166..b457b0a 100644 --- a/lib/widgets/seekbar.dart +++ b/lib/widgets/seekbar.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import 'package:raag/provider/audio_helper.dart'; import 'package:raag/provider/player_provider.dart'; @@ -10,10 +11,11 @@ class SeekBar extends StatefulWidget { class _SeekBarState extends State { @override Widget build(BuildContext context) { + final provider = Provider.of(context); return Row( children: [ Text( - formatDuration(audioManagerInstance.position), + formatDuration(provider.audioManagerInstance.position), style: Theme.of(context).textTheme.subtitle2, ), Expanded( @@ -35,28 +37,32 @@ class _SeekBarState extends State { inactiveTrackColor: Theme.of(context).dividerColor, ), child: Slider( - value: slider ?? 0, + value: provider.slider ?? 0, onChanged: (value) { setState(() { - slider = value; + provider.slider = value; }); }, onChangeEnd: (value) { - if (audioManagerInstance.duration != null) { + if (provider.audioManagerInstance.duration != null) { Duration msec = Duration( milliseconds: - (audioManagerInstance.duration.inMilliseconds * - value) - .round()); - audioManagerInstance.seekTo(msec); + (provider.audioManagerInstance.duration + .inMilliseconds * + value) + .round()); + provider.audioManagerInstance.seekTo(msec); } }, )), ), ), Text( - formatDuration(audioManagerInstance.duration), - style: Theme.of(context).textTheme.subtitle2, + formatDuration(provider.audioManagerInstance.duration), + style: Theme + .of(context) + .textTheme + .subtitle2, ), ], ); diff --git a/pubspec.lock b/pubspec.lock index b54aac5..6bdd1ca 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -21,7 +21,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.3" + version: "2.5.0" audio_manager: dependency: "direct main" description: @@ -49,21 +49,21 @@ packages: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.5" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" clipboard: dependency: "direct main" description: @@ -77,14 +77,14 @@ packages: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.5" + version: "1.15.0" connectivity: dependency: "direct main" description: @@ -161,21 +161,21 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" ffi: dependency: transitive description: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "1.0.0" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "5.2.1" + version: "6.1.0" flutter: dependency: "direct main" description: flutter @@ -233,20 +233,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.4" - intl: - dependency: transitive - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.1" js: dependency: transitive description: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3-nullsafety.3" + version: "0.6.3" json_annotation: dependency: transitive description: @@ -267,14 +260,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.3" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.6" + version: "1.3.0" nested: dependency: transitive description: @@ -288,42 +281,42 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.3" + version: "1.8.0" path_provider: dependency: "direct main" description: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "1.6.27" + version: "2.0.1" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+2" + version: "2.0.0" path_provider_macos: dependency: transitive description: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.4+8" + version: "2.0.0" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "2.0.0" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.4+1" + version: "2.0.0" pedantic: dependency: transitive description: @@ -344,7 +337,7 @@ packages: name: platform url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "3.0.0" plugin_platform_interface: dependency: transitive description: @@ -358,7 +351,7 @@ packages: name: process url: "https://pub.dartlang.org" source: hosted - version: "3.0.13" + version: "4.1.0" provider: dependency: "direct main" description: @@ -386,42 +379,42 @@ packages: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.12+2" + version: "2.0.3" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.2+2" + version: "2.0.0" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+10" + version: "2.0.0" shared_preferences_platform_interface: dependency: transitive description: name: shared_preferences_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.0" shared_preferences_web: dependency: transitive description: name: shared_preferences_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.2+7" + version: "2.0.0" shared_preferences_windows: dependency: transitive description: name: shared_preferences_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+1" + version: "2.0.0" sky_engine: dependency: transitive description: flutter @@ -433,7 +426,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.4" + version: "1.8.1" sqflite: dependency: "direct main" description: @@ -454,7 +447,7 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.6" + version: "1.10.0" states_rebuilder: dependency: transitive description: @@ -468,14 +461,14 @@ packages: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" synchronized: dependency: transitive description: @@ -489,28 +482,28 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.6" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.5" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.5" + version: "2.1.0" webview_flutter: dependency: "direct main" description: @@ -524,14 +517,14 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "1.7.3" + version: "2.0.0" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.1.2" + version: "0.2.0" xml: dependency: transitive description: @@ -547,5 +540,5 @@ packages: source: hosted version: "1.7.5" sdks: - dart: ">=2.12.0-0.0 <3.0.0" + dart: ">=2.12.0-259.9.beta <3.0.0" flutter: ">=1.22.2" diff --git a/pubspec.yaml b/pubspec.yaml index 05676f8..fd5d77f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,11 +32,11 @@ dependencies: flutter_audio_query: ^0.3.5+6 fluttertoast: ^7.1.1 marquee: ^1.6.1 - path_provider: any + path_provider: ^2.0.0-nullsafety.1 provider: ^4.3.2+2 rflutter_alert: ^1.1.0 settings_ui: ^0.5.0 - shared_preferences: ^0.5.10 + shared_preferences: ^2.0.3 webview_flutter: ^1.0.7 youtube_explode_dart: ^1.3.0