fix #57
This commit is contained in:
parent
043c9d9d9f
commit
b4d27154fe
4 changed files with 53 additions and 28 deletions
|
@ -1,3 +1,4 @@
|
|||
## Unreleased Changes
|
||||
|
||||
- Upgrade to Flutter 3.7 & dependency updates
|
||||
- Fix album cover bug on currently playing page (#57)
|
||||
|
|
|
@ -96,6 +96,10 @@ abstract class _AudioStore with Store {
|
|||
String get positionString =>
|
||||
utils.msToTimeString(currentPositionStream.value ?? const Duration(seconds: 0));
|
||||
|
||||
@observable
|
||||
late ObservableStream<List<QueueItem>> queueStream =
|
||||
_audioPlayerRepository.managedQueueInfo.queueItemsStream.asObservable();
|
||||
|
||||
@readonly
|
||||
late List<QueueItem> _queue = [];
|
||||
|
||||
|
|
|
@ -93,6 +93,22 @@ mixin _$AudioStore on _AudioStore, Store {
|
|||
});
|
||||
}
|
||||
|
||||
late final _$queueStreamAtom =
|
||||
Atom(name: '_AudioStore.queueStream', context: context);
|
||||
|
||||
@override
|
||||
ObservableStream<List<QueueItem>> get queueStream {
|
||||
_$queueStreamAtom.reportRead();
|
||||
return super.queueStream;
|
||||
}
|
||||
|
||||
@override
|
||||
set queueStream(ObservableStream<List<QueueItem>> value) {
|
||||
_$queueStreamAtom.reportWrite(value, super.queueStream, () {
|
||||
super.queueStream = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$_queueAtom = Atom(name: '_AudioStore._queue', context: context);
|
||||
|
||||
List<QueueItem> get queue {
|
||||
|
@ -221,6 +237,7 @@ mixin _$AudioStore on _AudioStore, Store {
|
|||
currentSongStream: ${currentSongStream},
|
||||
playingStream: ${playingStream},
|
||||
currentPositionStream: ${currentPositionStream},
|
||||
queueStream: ${queueStream},
|
||||
playableStream: ${playableStream},
|
||||
queueIndexStream: ${queueIndexStream},
|
||||
shuffleModeStream: ${shuffleModeStream},
|
||||
|
|
|
@ -2,9 +2,9 @@ import 'dart:async';
|
|||
|
||||
import 'package:fimber/fimber.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
import '../../domain/entities/queue_item.dart';
|
||||
import '../state/audio_store.dart';
|
||||
import 'album_art.dart';
|
||||
|
||||
|
@ -27,27 +27,33 @@ class _AlbumArtSwipeState extends State<AlbumArtSwipe> {
|
|||
int seekingCount = 0;
|
||||
bool get isSeekActive => seekingCount <= 0;
|
||||
|
||||
late StreamSubscription _streamSubscription;
|
||||
late StreamSubscription _indexStreamSubscription;
|
||||
late StreamSubscription _queueStreamSubscription;
|
||||
late List<QueueItem> _queue;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = PageController(initialPage: audioStore.queueIndexStream.value!);
|
||||
|
||||
_streamSubscription = audioStore.queueIndexStream.listen((value) {
|
||||
AlbumArtSwipe._log.d('index: $value');
|
||||
_queue = audioStore.queue;
|
||||
_queueStreamSubscription = audioStore.queueStream.listen((value) {
|
||||
setState(() {
|
||||
_queue = value;
|
||||
});
|
||||
});
|
||||
|
||||
_indexStreamSubscription = audioStore.queueIndexStream.listen((value) {
|
||||
if (value == null) return;
|
||||
AlbumArtSwipe._log.d('queue item: ${audioStore.queue[value]}');
|
||||
|
||||
// only animate if not already on the same page (rounded)
|
||||
if (controller.positions.isNotEmpty && value != controller.page?.round()) {
|
||||
if ((value - (controller.page ?? value)).abs() > 1.6) {
|
||||
AlbumArtSwipe._log.d('jump to: $value');
|
||||
if (controller.positions.isNotEmpty) {
|
||||
final diff = (value - (controller.page ?? value)).abs();
|
||||
if (diff < 0.5 || diff > 1.5) {
|
||||
seekingCount++;
|
||||
controller.jumpToPage(value);
|
||||
seekingCount--;
|
||||
} else {
|
||||
AlbumArtSwipe._log.d('seek to: $value');
|
||||
seekingCount++;
|
||||
controller
|
||||
.animateToPage(
|
||||
|
@ -64,7 +70,8 @@ class _AlbumArtSwipeState extends State<AlbumArtSwipe> {
|
|||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
_streamSubscription.cancel();
|
||||
_queueStreamSubscription.cancel();
|
||||
_indexStreamSubscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
@ -72,24 +79,20 @@ class _AlbumArtSwipeState extends State<AlbumArtSwipe> {
|
|||
Widget build(BuildContext context) {
|
||||
const Key key = ValueKey('ALBUM_ART_SWIPE');
|
||||
|
||||
return Observer(builder: (context) {
|
||||
AlbumArtSwipe._log.d('Build PageView');
|
||||
final queue = audioStore.queue;
|
||||
return PageView.builder(
|
||||
key: key,
|
||||
controller: controller,
|
||||
clipBehavior: Clip.none,
|
||||
itemBuilder: (_, index) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
|
||||
child: AlbumArt(song: queue[index].song),
|
||||
),
|
||||
);
|
||||
},
|
||||
onPageChanged: _conditionalSeek,
|
||||
);
|
||||
});
|
||||
return PageView.builder(
|
||||
key: key,
|
||||
controller: controller,
|
||||
clipBehavior: Clip.none,
|
||||
itemBuilder: (_, index) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
|
||||
child: AlbumArt(song: _queue[index].song),
|
||||
),
|
||||
);
|
||||
},
|
||||
onPageChanged: _conditionalSeek,
|
||||
);
|
||||
}
|
||||
|
||||
void _conditionalSeek(int index) {
|
||||
|
|
Loading…
Add table
Reference in a new issue