Skip to content

Commit

Permalink
Pass song id to play() instead of list index
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinkey04 committed Feb 8, 2022
1 parent d70ab09 commit b9e73ea
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 57 deletions.
9 changes: 5 additions & 4 deletions lib/provider/player_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PlayerProvider extends ChangeNotifier {
androidNotificationChannelName: appName,
androidNotificationOngoing: true,
androidShowNotificationBadge: true,
androidNotificationIcon: "mipmap/launcher_icon",
androidNotificationIcon: "mipmap/ic_launcher",
),
);
positionStream = await _audioHandler!.customAction('positionStream');
Expand All @@ -50,12 +50,13 @@ class PlayerProvider extends ChangeNotifier {
if (globalQueue.isNotEmpty) await _audioHandler!.addQueueItems(globalQueue);
}

play(int index) async {
play(String id) async {
if (globalQueue.isEmpty) {
return;
}
globalIndex = index;
await _audioHandler!.skipToQueueItem(index);
globalIndex =
globalQueue.indexWhere((element) => element.id == id);
await _audioHandler!.skipToQueueItem(globalIndex!);
await _audioHandler!.play();
}

Expand Down
9 changes: 3 additions & 6 deletions lib/view/playback_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ class _PlayBackControlsState extends State<PlayBackControls>
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
child: BackdropFilter(
filter: new ImageFilter.blur(sigmaX: 20.0, sigmaY: 20.0),
child: CollapsedControls(
provider: playerProvider,
panelController: panelController,
),
child: CollapsedControls(
provider: playerProvider,
panelController: panelController,
),
),
renderPanelSheet: false,
Expand Down
33 changes: 19 additions & 14 deletions lib/widgets/collapsed_controls.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';

Expand All @@ -17,20 +19,23 @@ class CollapsedControls extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height * 0.2,
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SeekBar(),
PlayBackControlButtons(
provider: provider,
isCollapsed: true,
panelController: panelController,
),
],
return BackdropFilter(
filter: new ImageFilter.blur(sigmaX: 20.0, sigmaY: 20.0),
child: Container(
height: MediaQuery.of(context).size.height * 0.2,
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SeekBar(),
PlayBackControlButtons(
provider: provider,
isCollapsed: true,
panelController: panelController,
),
],
),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/song_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SongCard extends StatelessWidget {
borderRadius: BorderRadius.all(Radius.circular(24))),
child: InkWell(
onTap: () {
provider.play(songIndex);
provider.play(song.id.toString());
playPauseController.forward();
},
child: Card(
Expand Down
64 changes: 32 additions & 32 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ packages:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.8"
version: "3.1.11"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -189,7 +189,7 @@ packages:
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.2"
version: "4.3.3"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -309,21 +309,21 @@ packages:
name: just_audio
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.18"
version: "0.9.19"
just_audio_platform_interface:
dependency: transitive
description:
name: just_audio_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
version: "4.1.0"
just_audio_web:
dependency: transitive
description:
name: just_audio_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.4"
marquee:
dependency: "direct main"
description:
Expand Down Expand Up @@ -358,21 +358,21 @@ packages:
name: on_audio_query
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.3"
version: "2.6.0"
on_audio_query_platform_interface:
dependency: transitive
description:
name: on_audio_query_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.4.0"
on_audio_query_web:
dependency: transitive
description:
name: on_audio_query_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2"
version: "1.3.2+2"
open_file:
dependency: "direct main"
description:
Expand All @@ -393,14 +393,14 @@ packages:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.7"
version: "2.0.8"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.9"
version: "2.0.11"
path_provider_ios:
dependency: transitive
description:
Expand All @@ -414,28 +414,28 @@ packages:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
version: "2.1.5"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.5"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.0.3"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
version: "2.0.5"
pedantic:
dependency: transitive
description:
Expand All @@ -456,14 +456,14 @@ packages:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.1.2"
process:
dependency: transitive
description:
Expand All @@ -477,7 +477,7 @@ packages:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.1"
version: "6.0.2"
receive_sharing_intent:
dependency: "direct main"
description:
Expand Down Expand Up @@ -505,28 +505,28 @@ packages:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.9"
version: "2.0.13"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.9"
version: "2.0.10"
shared_preferences_ios:
dependency: transitive
description:
name: shared_preferences_ios
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.0.9"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.4"
shared_preferences_macos:
dependency: transitive
description:
Expand All @@ -547,14 +547,14 @@ packages:
name: shared_preferences_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.3"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.4"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -580,14 +580,14 @@ packages:
name: sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0+4"
version: "2.0.2"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1+1"
version: "2.2.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -664,42 +664,42 @@ packages:
name: webview_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
version: "2.8.0"
webview_flutter_android:
dependency: transitive
description:
name: webview_flutter_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
version: "2.8.2"
webview_flutter_platform_interface:
dependency: transitive
description:
name: webview_flutter_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.2"
version: "1.8.1"
webview_flutter_wkwebview:
dependency: transitive
description:
name: webview_flutter_wkwebview
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
version: "2.7.1"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
version: "2.3.11"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
version: "0.2.0+1"
xml:
dependency: transitive
description:
Expand All @@ -722,5 +722,5 @@ packages:
source: hosted
version: "1.10.9+1"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=2.15.0 <3.0.0"
flutter: ">=2.5.0"

0 comments on commit b9e73ea

Please sign in to comment.