✨ Player queue remove, reorder
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:math' as math;
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -214,7 +215,9 @@ class _DesktopLayout extends StatelessWidget {
|
|||||||
ViewMode.cover => Center(
|
ViewMode.cover => Center(
|
||||||
key: const ValueKey('cover'),
|
key: const ValueKey('cover'),
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: const BoxConstraints(maxWidth: 480),
|
constraints: BoxConstraints(
|
||||||
|
maxWidth: math.min(480, MediaQuery.sizeOf(context).width * 0.4),
|
||||||
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
@@ -252,7 +255,12 @@ class _DesktopLayout extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: Center(
|
child: Center(
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: const BoxConstraints(maxWidth: 480),
|
constraints: BoxConstraints(
|
||||||
|
maxWidth: math.min(
|
||||||
|
480,
|
||||||
|
MediaQuery.sizeOf(context).width * 0.4,
|
||||||
|
),
|
||||||
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
@@ -321,7 +329,12 @@ class _DesktopLayout extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: Center(
|
child: Center(
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: const BoxConstraints(maxWidth: 480),
|
constraints: BoxConstraints(
|
||||||
|
maxWidth: math.min(
|
||||||
|
480,
|
||||||
|
MediaQuery.sizeOf(context).width * 0.4,
|
||||||
|
),
|
||||||
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
@@ -364,7 +377,7 @@ class _DesktopLayout extends StatelessWidget {
|
|||||||
top: 0,
|
top: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
width: MediaQuery.sizeOf(context).width * 0.5,
|
width: MediaQuery.sizeOf(context).width * 0.5,
|
||||||
child: _QueueView(player: player),
|
child: _QueueView(player: player).padding(right: 64),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -1076,9 +1089,15 @@ class _QueueView extends HookConsumerWidget {
|
|||||||
return const Center(child: Text('No tracks in queue'));
|
return const Center(child: Text('No tracks in queue'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ListView.builder(
|
return ReorderableListView.builder(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
itemCount: playlist.medias.length,
|
itemCount: playlist.medias.length,
|
||||||
|
onReorder: (oldIndex, newIndex) {
|
||||||
|
if (oldIndex < newIndex) {
|
||||||
|
newIndex -= 1;
|
||||||
|
}
|
||||||
|
player.move(oldIndex, newIndex);
|
||||||
|
},
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final media = playlist.medias[index];
|
final media = playlist.medias[index];
|
||||||
final isCurrent = index == playlist.index;
|
final isCurrent = index == playlist.index;
|
||||||
@@ -1086,11 +1105,22 @@ class _QueueView extends HookConsumerWidget {
|
|||||||
final trackAsync = ref.watch(trackByPathProvider(trackPath));
|
final trackAsync = ref.watch(trackByPathProvider(trackPath));
|
||||||
|
|
||||||
return trackAsync.when(
|
return trackAsync.when(
|
||||||
loading: () => const SizedBox(
|
loading: () => SizedBox(
|
||||||
|
key: Key('loading_$index'),
|
||||||
height: 72,
|
height: 72,
|
||||||
child: Center(child: CircularProgressIndicator()),
|
child: const Center(child: CircularProgressIndicator()),
|
||||||
),
|
),
|
||||||
error: (error, stack) => TrackTile(
|
error: (error, stack) => Dismissible(
|
||||||
|
key: Key('queue_item_error_$index'),
|
||||||
|
direction: DismissDirection.endToStart,
|
||||||
|
background: Container(
|
||||||
|
color: Colors.red,
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
padding: const EdgeInsets.only(right: 20),
|
||||||
|
child: const Icon(Icons.delete, color: Colors.white),
|
||||||
|
),
|
||||||
|
onDismissed: (direction) => player.remove(index),
|
||||||
|
child: TrackTile(
|
||||||
track: db.Track(
|
track: db.Track(
|
||||||
id: -1,
|
id: -1,
|
||||||
path: trackPath,
|
path: trackPath,
|
||||||
@@ -1109,11 +1139,34 @@ class _QueueView extends HookConsumerWidget {
|
|||||||
onTap: () => player.jump(index),
|
onTap: () => player.jump(index),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
),
|
),
|
||||||
data: (track) => TrackTile(
|
),
|
||||||
leading: Text(
|
data: (track) => Dismissible(
|
||||||
|
key: Key('queue_item_$index'),
|
||||||
|
direction: DismissDirection.endToStart,
|
||||||
|
background: Container(
|
||||||
|
color: Colors.red,
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
padding: const EdgeInsets.only(right: 20),
|
||||||
|
child: const Icon(Icons.delete, color: Colors.white),
|
||||||
|
),
|
||||||
|
onDismissed: (direction) => player.remove(index),
|
||||||
|
child: TrackTile(
|
||||||
|
leading: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.drag_handle,
|
||||||
|
size: 20,
|
||||||
|
color: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.onSurface.withOpacity(0.5),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
(index + 1).toString().padLeft(2, '0'),
|
(index + 1).toString().padLeft(2, '0'),
|
||||||
style: TextStyle(fontSize: 14),
|
style: TextStyle(fontSize: 14),
|
||||||
).padding(right: 12),
|
),
|
||||||
|
],
|
||||||
|
).padding(right: 4),
|
||||||
track:
|
track:
|
||||||
track ??
|
track ??
|
||||||
db.Track(
|
db.Track(
|
||||||
@@ -1134,6 +1187,7 @@ class _QueueView extends HookConsumerWidget {
|
|||||||
onTap: () => player.jump(index),
|
onTap: () => player.jump(index),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user