Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Edge progress bar, card layout overhaul, zoom-safe UI

Nathan Poulson02070d5623a0
diff --git a/lib/screens/absorbing_screen.dart b/lib/screens/absorbing_screen.dart
index 3ef9624b..0eaa0e50 100644
--- a/lib/screens/absorbing_screen.dart
+++ b/lib/screens/absorbing_screen.dart
@@ -39,6 +39,19 @@ class AbsorbingScreen extends StatefulWidget {
class _AbsorbingScreenState extends State<AbsorbingScreen> {
final _player = AudioPlayerService();
final _pageController = PageController(viewportFraction: 0.92);
+ final _cardKeys = <String, GlobalKey<AbsorbingCardState>>{};
+
+ GlobalKey<AbsorbingCardState> _cardKey(String absorbingKey) {
+ return _cardKeys.putIfAbsent(absorbingKey, () => GlobalKey<AbsorbingCardState>());
+ }
+
+ void _expandCurrentCard() {
+ final books = _getAbsorbingBooks(context.read<LibraryProvider>());
+ if (books.isEmpty) return;
+ final idx = books.length == 1 ? 0 : (_pageController.hasClients ? (_pageController.page ?? 0).round().clamp(0, books.length - 1) : 0);
+ final key = _absorbingKey(books[idx]);
+ _cardKeys[key]?.currentState?.expandCard(context);
+ }
final _cast = ChromecastService();
@@ -465,7 +478,7 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
// ── Header ──
AbsorbPageHeader(
title: 'Absorbing',
- padding: const EdgeInsets.fromLTRB(20, 12, 12, 0),
+ padding: const EdgeInsets.fromLTRB(20, 4, 12, 0),
trailing: GestureDetector(
onTap: () {
final newVal = !lib.isManualOffline;
@@ -549,9 +562,23 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
// ── Page Dots ──
if (books.length > 1)
Padding(
- padding: const EdgeInsets.only(top: 8, bottom: 4),
+ padding: const EdgeInsets.only(top: 4, bottom: 2),
child: _PageDots(count: books.length, controller: _pageController),
),
+ // ── Expand button ──
+ if (books.isNotEmpty)
+ Align(
+ alignment: Alignment.centerRight,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: _expandCurrentCard,
+ child: Padding(
+ padding: const EdgeInsets.only(right: 28),
+ child: Icon(Icons.open_in_full_rounded, size: 15,
+ color: cs.onSurface.withValues(alpha: 0.4)),
+ ),
+ ),
+ ),
// ── Cards (refreshable) ──
Expanded(
child: showBlockingLoader
@@ -561,10 +588,10 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
: books.length == 1
? LayoutBuilder(
builder: (context, constraints) {
- final vPad = (constraints.maxHeight * 0.02).clamp(6.0, 24.0);
+ final vPad = (constraints.maxHeight * 0.01).clamp(2.0, 16.0);
return Padding(
padding: EdgeInsets.symmetric(horizontal: 4, vertical: vPad),
- child: RepaintBoundary(child: AbsorbingCard(key: ValueKey(_absorbingKey(books[0])), item: books[0], player: _player)),
+ child: RepaintBoundary(child: AbsorbingCard(key: _cardKey(_absorbingKey(books[0])), item: books[0], player: _player)),
);
},
)
@@ -577,7 +604,7 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
itemBuilder: (_, i) => LayoutBuilder(
builder: (context, constraints) {
final cardWidth = constraints.maxWidth;
- final vPad = (constraints.maxHeight * 0.02).clamp(6.0, 24.0);
+ final vPad = (constraints.maxHeight * 0.01).clamp(2.0, 16.0);
return AnimatedBuilder(
animation: _pageController,
builder: (context, child) {
@@ -614,7 +641,7 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
),
);
},
- child: RepaintBoundary(child: AbsorbingCard(key: ValueKey(_absorbingKey(books[i])), item: books[i], player: _player)),
+ child: RepaintBoundary(child: AbsorbingCard(key: _cardKey(_absorbingKey(books[i])), item: books[i], player: _player)),
);
},
),
diff --git a/lib/screens/car_mode_screen.dart b/lib/screens/car_mode_screen.dart
index 914f869e..c3b24c4a 100644
--- a/lib/screens/car_mode_screen.dart
+++ b/lib/screens/car_mode_screen.dart
@@ -428,30 +428,30 @@ class _CarModeScreenState extends State<CarModeScreen>
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
- GestureDetector(
+ Flexible(child: GestureDetector(
onTap: player.hasBook ? player.skipToPreviousChapter : null,
child: SizedBox(width: skipSize, height: skipSize,
child: Center(child: Icon(Icons.skip_previous_rounded,
size: skipIconSize * 0.85,
color: player.hasBook ? Colors.white70 : Colors.white24))),
- ),
- GestureDetector(
+ )),
+ Flexible(child: GestureDetector(
onTap: player.hasBook ? () => player.skipBackward(_backSkip) : null,
child: SizedBox(width: skipSize, height: skipSize,
child: Center(child: _buildSkipIcon(_backSkip, false, player.hasBook, skipIconSize))),
- ),
- GestureDetector(
+ )),
+ Flexible(child: GestureDetector(
onTap: player.hasBook ? () => player.skipForward(_forwardSkip) : null,
child: SizedBox(width: skipSize, height: skipSize,
child: Center(child: _buildSkipIcon(_forwardSkip, true, player.hasBook, skipIconSize))),
- ),
- GestureDetector(
+ )),
+ Flexible(child: GestureDetector(
onTap: player.hasBook ? player.skipToNextChapter : null,
child: SizedBox(width: skipSize, height: skipSize,
child: Center(child: Icon(Icons.skip_next_rounded,
size: skipIconSize * 0.85,
color: player.hasBook ? Colors.white70 : Colors.white24))),
- ),
+ )),
],
),
),
diff --git a/lib/widgets/absorbing_card.dart b/lib/widgets/absorbing_card.dart
index 82755a35..f3402acd 100644
--- a/lib/widgets/absorbing_card.dart
+++ b/lib/widgets/absorbing_card.dart
@@ -13,6 +13,7 @@ import '../services/playback_history_service.dart';
import 'book_detail_sheet.dart';
import 'episode_list_sheet.dart';
import 'equalizer_sheet.dart';
+import 'card_edge_progress_bar.dart';
import 'card_progress_bar.dart';
import 'card_playback_controls.dart';
import 'card_buttons.dart';
@@ -46,6 +47,8 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
String _buttonLayout = PlayerSettings.defaultButtonLayout;
bool _rectangleCovers = false;
bool _coverPlayButton = false;
+ bool _speedAdjustedTime = true;
+ final ValueNotifier<bool> _edgeBarExpanded = ValueNotifier(false);
@override
bool get wantKeepAlive => true;
@@ -135,6 +138,9 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
PlayerSettings.getCoverPlayButton().then((v) {
if (mounted && v != _coverPlayButton) setState(() => _coverPlayButton = v);
});
+ PlayerSettings.getSpeedAdjustedTime().then((v) {
+ if (mounted && v != _speedAdjustedTime) setState(() => _speedAdjustedTime = v);
+ });
}
void _onDownloadChanged() { if (mounted) setState(() {}); }
@@ -259,6 +265,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
DownloadService().removeListener(_onDownloadChanged);
_chapterTrackSub?.cancel();
_blurredCover?.dispose();
+ _edgeBarExpanded.dispose();
super.dispose();
}
@@ -374,6 +381,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
_blurredCover = null;
}
+ final showBookBar = (!_isPodcastEpisode || _chapters.isNotEmpty) && (!lib.isPodcastLibrary || _chapters.isNotEmpty);
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24),
@@ -451,49 +459,52 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
final compact = cardConstraints.maxHeight < 600 * textScale;
return Column(
children: [
- // ── Stats row ──
- Padding(
- padding: EdgeInsets.fromLTRB(24, compact ? 6 : 10, 24, 0),
- child: Row(
- children: [
- Text('${(bookProgress * 100).clamp(0, 100).toStringAsFixed(1)}%',
- style: tt.labelMedium?.copyWith(
- color: isDark ? Colors.white.withValues(alpha: 0.95) : Colors.black.withValues(alpha: 0.85),
- fontWeight: FontWeight.w800, fontSize: compact ? 12 : 15,
+ // ── Stats row (fades when edge bar expands) ──
+ ValueListenableBuilder<bool>(
+ valueListenable: _edgeBarExpanded,
+ builder: (_, expanded, child) => AnimatedOpacity(
+ opacity: expanded ? 0.0 : 1.0,
+ duration: const Duration(milliseconds: 200),
+ child: child,
+ ),
+ child: Padding(
+ padding: EdgeInsets.fromLTRB(24, compact ? 6 : 10, 24, 0),
+ child: StreamBuilder<Duration>(
+ stream: widget.player.absolutePositionStream,
+ builder: (_, snap) {
+ final pos = _isActive
+ ? (snap.data?.inMilliseconds ?? 0) / 1000.0
+ : bookProgress * _effectiveDuration;
+ final speed = _speedAdjustedTime && _isActive ? widget.player.speed : 1.0;
+ final elapsed = pos / speed;
+ final remaining = (_effectiveDuration - pos) / speed;
+ final timeStyle = tt.labelSmall?.copyWith(
+ color: isDark ? Colors.white.withValues(alpha: 0.55) : Colors.black.withValues(alpha: 0.45),
+ fontWeight: FontWeight.w500, fontSize: compact ? 10 : 11,
+ fontFeatures: const [FontFeature.tabularFigures()],
shadows: [Shadow(color: isDark ? Colors.black.withValues(alpha: 0.6) : Colors.white.withValues(alpha: 0.6), blurRadius: 4)],
- )),
- const Spacer(),
- if (totalChapters > 0 && (!_isPodcastEpisode || _chapters.isNotEmpty))
- Text('Ch ${(chapterIdx + 1).clamp(1, totalChapters)} / $totalChapters',
- style: tt.labelMedium?.copyWith(
- color: isDark ? Colors.white.withValues(alpha: 0.85) : Colors.black.withValues(alpha: 0.75),
- fontWeight: FontWeight.w700, fontSize: compact ? 11 : 14,
- shadows: [Shadow(color: isDark ? Colors.black.withValues(alpha: 0.6) : Colors.white.withValues(alpha: 0.6), blurRadius: 4)],
- )),
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () => _expandCard(context),
- child: Padding(
- padding: const EdgeInsets.all(8),
- child: Icon(Icons.open_in_full_rounded, size: compact ? 14 : 17,
- color: isDark ? Colors.white.withValues(alpha: 0.6) : Colors.black.withValues(alpha: 0.5)),
- ),
- ),
- ],
+ );
+ return Row(
+ children: [
+ if (_effectiveDuration > 0)
+ Text(_fmtTime(elapsed), style: timeStyle),
+ const Spacer(),
+ Text('${(bookProgress * 100).clamp(0, 100).toStringAsFixed(1)}%',
+ style: timeStyle),
+ const Spacer(),
+ if (_effectiveDuration > 0)
+ Text('-${_fmtTime(remaining)}', style: timeStyle),
+ ],
+ );
+ },
+ ),
),
),
- // ── Book progress bar ──
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 20),
- child: CardDualProgressBar(player: widget.player, accent: accent, isActive: _isActive, staticProgress: progress, staticDuration: _effectiveDuration, chapters: _chapters, showBookBar: (!_isPodcastEpisode || _chapters.isNotEmpty) && (!lib.isPodcastLibrary || _chapters.isNotEmpty), showChapterBar: false, itemId: _itemId, compact: compact),
- ),
- SizedBox(height: compact ? 2 : 6),
// ── Cover with title/author/chapter overlaid + download badge ──
- const Spacer(),
- Padding(
+ Expanded(child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: ListenableBuilder(
- listenable: ChromecastService(),
+ listenable: Listenable.merge([ChromecastService(), widget.player]),
builder: (context, _) => LayoutBuilder(
builder: (context, constraints) {
final maxW = constraints.maxWidth * 0.75;
@@ -513,8 +524,8 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
final castService = ChromecastService();
final isCastingThis = castService.isCasting && castService.castingItemId == _itemId;
final coverPlaying = isCastingThis ? castService.isPlaying : (_isActive && widget.player.isPlaying);
- final coverLoading = _isStarting || (_isActive && widget.player.isLoadingOrBuffering);
- return GestureDetector(
+ final coverLoading = _isStarting || (_isActive && widget.player.isLoadingOrBuffering && !widget.player.isPlaying);
+ return Center(child: GestureDetector(
onTap: _coverPlayButton ? () {
if (isCastingThis) {
castService.togglePlayPause();
@@ -523,7 +534,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
} else {
_startPlayback();
}
- } : () => _expandCard(context),
+ } : null,
child: Container(
width: coverW,
height: coverH,
@@ -645,21 +656,22 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
),
),
),
- );
+ ));
},
),
),
),
- const Spacer(),
+ ),
// ── Chapter pill-scrubber ──
+ SizedBox(height: compact ? 6 : 10),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CardDualProgressBar(player: widget.player, accent: accent, isActive: _isActive, staticProgress: (_isPodcastEpisode && _chapters.isEmpty) ? 0.0 : progress, staticDuration: (_isPodcastEpisode && _chapters.isEmpty) ? widget.player.totalDuration : _effectiveDuration, chapters: _chapters, showBookBar: false, showChapterBar: true, chapterName: (_isPodcastEpisode && _chapters.isEmpty) ? (widget.player.currentEpisodeTitle ?? widget.player.currentTitle ?? _title) : (_episodeId != null && !_isActive ? (_recentEpisode?['title'] as String? ?? _title) : _chapterName(chapterIdx)), chapterIndex: chapterIdx, totalChapters: totalChapters, itemId: _itemId, compact: compact),
),
// ── Controls ──
- const Spacer(),
+ SizedBox(height: compact ? 6 : 10),
Padding(
- padding: const EdgeInsets.symmetric(horizontal: 20),
+ padding: const EdgeInsets.symmetric(horizontal: 10),
child: CardPlaybackControls(
player: widget.player,
accent: accent,
@@ -670,9 +682,13 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
showPlayButton: !_coverPlayButton,
),
),
- const Spacer(),
+ SizedBox(height: compact ? 6 : 12),
// ── Button grid + more menu ──
- Padding(
+ MediaQuery(
+ data: MediaQuery.of(context).copyWith(
+ textScaler: TextScaler.noScaling,
+ ),
+ child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: FittedBox(
fit: BoxFit.scaleDown,
@@ -722,9 +738,27 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
),
),
),
+ ),
],
- );
+ );
}),
+ // Edge progress bar (thin strip at top of card)
+ if (showBookBar)
+ Positioned(
+ top: 0,
+ left: 0,
+ right: 0,
+ child: CardEdgeProgressBar(
+ player: widget.player,
+ accent: accent,
+ isActive: _isActive,
+ staticProgress: progress,
+ staticDuration: _effectiveDuration,
+ chapters: _chapters,
+ itemId: _itemId,
+ expandedNotifier: _edgeBarExpanded,
+ ),
+ ),
],
),
),
@@ -794,7 +828,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
);
}
- void _expandCard(BuildContext context) {
+ void expandCard(BuildContext context) {
AppShell.setExpandedOpen(true);
Navigator.of(context, rootNavigator: true).push(
ExpandedCardRoute(
@@ -1191,7 +1225,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli
child: Column(children: [
Padding(padding: const EdgeInsets.symmetric(vertical: 12),
child: Container(width: 40, height: 4, decoration: BoxDecoration(color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.24), borderRadius: BorderRadius.circular(2)))),
- Text('Chapters', style: tt.titleMedium?.copyWith(fontWeight: FontWeight.w600)),
+ Text('Chapters (${chapters.length})', style: tt.titleMedium?.copyWith(fontWeight: FontWeight.w600)),
const SizedBox(height: 8),
Expanded(child: ListView.builder(
controller: sc, itemCount: chapters.length,
diff --git a/lib/widgets/card_edge_progress_bar.dart b/lib/widgets/card_edge_progress_bar.dart
new file mode 100644
index 00000000..cb0db5b6
--- /dev/null
+++ b/lib/widgets/card_edge_progress_bar.dart
@@ -0,0 +1,459 @@
+import 'dart:async';
+import 'dart:ui';
+import 'package:flutter/material.dart';
+import '../services/audio_player_service.dart';
+import '../services/chromecast_service.dart';
+
+// ─── EDGE PROGRESS BAR (thin strip at card top) ───────────────────────
+//
+// Default: 3.5px accent-colored strip flush at the card's top edge.
+// On horizontal drag or long-press: expands to a full scrubber overlay.
+
+class CardEdgeProgressBar extends StatefulWidget {
+ final AudioPlayerService player;
+ final Color accent;
+ final bool isActive;
+ final double staticProgress;
+ final double staticDuration;
+ final List<dynamic> chapters;
+ final String? itemId;
+ final ValueNotifier<bool>? expandedNotifier;
+
+ const CardEdgeProgressBar({
+ super.key,
+ required this.player,
+ required this.accent,
+ required this.isActive,
+ required this.staticProgress,
+ required this.staticDuration,
+ required this.chapters,
+ this.itemId,
+ this.expandedNotifier,
+ });
+
+ @override
+ State<CardEdgeProgressBar> createState() => _CardEdgeProgressBarState();
+}
+
+class _CardEdgeProgressBarState extends State<CardEdgeProgressBar>
+ with TickerProviderStateMixin, WidgetsBindingObserver {
+
+ // ── Smooth position tracking (same pattern as CardDualProgressBar) ──
+ late AnimationController _smoothTicker;
+ double _lastKnownPos = 0;
+ DateTime _lastPosTime = DateTime.now();
+ double _currentSpeed = 1.0;
+ bool _isPlaying = false;
+ bool _isCastMode = false;
+ StreamSubscription<Duration>? _posSub;
+ bool _speedAdjustedTime = true;
+
+ // ── Expand/collapse animation ──
+ late AnimationController _expandController;
+ double? _dragValue;
+ bool _showBookSlider = false;
+
+ static const _thinHeight = 3.5;
+ static const _expandedHeight = 50.0;
+ static const _hitTargetHeight = 28.0;
+
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addObserver(this);
+ _smoothTicker = AnimationController(vsync: this, duration: const Duration(days: 999));
+ _expandController = AnimationController(
+ vsync: this,
+ duration: const Duration(milliseconds: 250),
+ );
+ _expandController.addListener(() {
+ widget.expandedNotifier?.value = _expandController.value > 0.1;
+ });
+ _loadSettings();
+ _subscribePosition();
+ PlayerSettings.settingsChanged.addListener(_loadSettings);
+ ChromecastService().addListener(_onCastChanged);
+ }
+
+ void _loadSettings() {
+ PlayerSettings.getSpeedAdjustedTime().then((v) {
+ if (mounted && v != _speedAdjustedTime) setState(() => _speedAdjustedTime = v);
+ });
+ PlayerSettings.getShowBookSlider().then((v) {
+ if (mounted && v != _showBookSlider) {
+ setState(() => _showBookSlider = v);
+ }
+ });
+ }
+
+ void _onCastChanged() {
+ final cast = ChromecastService();
+ final wasCast = _isCastMode;
+ final isCast = widget.itemId != null && cast.isCasting && cast.castingItemId == widget.itemId;
+ if (wasCast != isCast) _subscribePosition();
+ }
+
+ @override
+ void didChangeAppLifecycleState(AppLifecycleState state) {
+ if (state == AppLifecycleState.resumed) _loadSettings();
+ }
+
+ @override
+ void didUpdateWidget(CardEdgeProgressBar old) {
+ super.didUpdateWidget(old);
+ if (old.isActive != widget.isActive) _subscribePosition();
+ }
+
+ void _syncTicker() {
+ if (_isPlaying && (widget.isActive || _isCastMode)) {
+ if (!_smoothTicker.isAnimating) _smoothTicker.repeat();
+ } else {
+ if (_smoothTicker.isAnimating) _smoothTicker.stop();
+ }
+ }
+
+ void _subscribePosition() {
+ _posSub?.cancel();
+ final cast = ChromecastService();
+ _isCastMode = widget.itemId != null && cast.isCasting && cast.castingItemId == widget.itemId;
+
+ if (_isCastMode) {
+ _lastKnownPos = cast.castPosition.inMilliseconds / 1000.0;
+ _lastPosTime = DateTime.now();
+ _currentSpeed = cast.castSpeed;
+ _isPlaying = cast.isPlaying;
+ _syncTicker();
+ _posSub = cast.castPositionStream?.listen((dur) {
+ final posSeconds = dur.inMilliseconds / 1000.0;
+ _lastKnownPos = posSeconds;
+ _lastPosTime = DateTime.now();
+ _currentSpeed = cast.castSpeed;
+ _isPlaying = cast.isPlaying;
+ _syncTicker();
+ });
+ } else if (widget.isActive) {
+ final seedPos = widget.staticProgress * widget.staticDuration;
+ _lastKnownPos = seedPos;
+ _lastPosTime = DateTime.now();
+
+ _posSub = widget.player.absolutePositionStream.listen((dur) {
+ final posSeconds = dur.inMilliseconds / 1000.0;
+
+ final seekTarget = widget.player.activeSeekTarget;
+ if (seekTarget != null) {
+ if ((posSeconds - seekTarget).abs() < 5.0) {
+ _lastKnownPos = posSeconds;
+ _lastPosTime = DateTime.now();
+ _currentSpeed = widget.player.speed;
+ _isPlaying = widget.player.isPlaying;
+ _syncTicker();
+ widget.player.clearSeekTarget();
+ return;
+ }
+ return;
+ }
+
+ if (_lastKnownPos > 10.0 && posSeconds < 2.0) return;
+
+ _lastKnownPos = posSeconds;
+ _lastPosTime = DateTime.now();
+ _currentSpeed = widget.player.speed;
+ _isPlaying = widget.player.isPlaying;
+ _syncTicker();
+ });
+ _currentSpeed = widget.player.speed;
+ _isPlaying = widget.player.isPlaying;
+ _syncTicker();
+ }
+ }
+
+ double get _smoothPos {
+ if (_isCastMode) {
+ if (!_isPlaying) return _lastKnownPos;
+ final elapsed = DateTime.now().difference(_lastPosTime).inMilliseconds / 1000.0;
+ return _lastKnownPos + elapsed * _currentSpeed;
+ }
+ final seekTarget = widget.player.activeSeekTarget;
+ if (seekTarget != null && (seekTarget - _lastKnownPos).abs() > 2.0) {
+ return seekTarget;
+ }
+ if (!widget.isActive || !_isPlaying) return _lastKnownPos;
+ final elapsed = DateTime.now().difference(_lastPosTime).inMilliseconds / 1000.0;
+ return _lastKnownPos + elapsed * _currentSpeed;
+ }
+
+ void _doSeek(int seekMs) {
+ if (_isCastMode) {
+ ChromecastService().seekTo(Duration(milliseconds: seekMs));
+ } else {
+ widget.player.seekTo(Duration(milliseconds: seekMs));
+ }
+ }
+
+ @override
+ void dispose() {
+ WidgetsBinding.instance.removeObserver(this);
+ PlayerSettings.settingsChanged.removeListener(_loadSettings);
+ ChromecastService().removeListener(_onCastChanged);
+ _posSub?.cancel();
+ _smoothTicker.dispose();
+ _expandController.dispose();
+ super.dispose();
+ }
+
+ static String _fmt(double s) {
+ if (s <= 0) return '0:00';
+ final h = (s / 3600).floor();
+ final m = ((s % 3600) / 60).floor();
+ final sec = (s % 60).floor();
+ if (h > 0) return '$h:${m.toString().padLeft(2, '0')}:${sec.toString().padLeft(2, '0')}';
+ return '$m:${sec.toString().padLeft(2, '0')}';
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final cs = Theme.of(context).colorScheme;
+ final tt = Theme.of(context).textTheme;
+ final isDark = Theme.of(context).brightness == Brightness.dark;
+ final cast = ChromecastService();
+ final active = widget.isActive || _isCastMode;
+
+ return ListenableBuilder(
+ listenable: Listenable.merge([_smoothTicker, _expandController]),
+ builder: (context, _) {
+ final staticPos = widget.staticProgress * widget.staticDuration;
+ final posS = active ? _smoothPos : staticPos;
+ final totalDur = _isCastMode
+ ? cast.castingDuration
+ : (widget.isActive ? widget.player.totalDuration : widget.staticDuration);
+ final speed = active ? _currentSpeed : 1.0;
+ final bookProgress = totalDur > 0 ? (posS / totalDur).clamp(0.0, 1.0) : 0.0;
+ final speedDiv = _speedAdjustedTime ? speed : 1.0;
+ final bookElapsed = posS / speedDiv;
+ final bookRemaining = (totalDur - posS) / speedDiv;
+
+ final expandT = CurvedAnimation(
+ parent: _expandController,
+ curve: Curves.easeOutCubic,
+ reverseCurve: Curves.easeInCubic,
+ ).value;
+
+ final totalHeight = lerpDouble(_hitTargetHeight, _expandedHeight, expandT)!;
+ final barHeight = lerpDouble(_thinHeight, 8.0, expandT)!;
+ final displayProgress = _dragValue ?? bookProgress;
+
+ final interactive = active && _showBookSlider;
+ return GestureDetector(
+ behavior: HitTestBehavior.translucent,
+ onHorizontalDragStart: interactive ? (d) {
+ if (!_expandController.isAnimating && _expandController.value < 1.0) {
+ _expandController.forward();
+ }
+ final box = context.findRenderObject() as RenderBox;
+ setState(() => _dragValue = (d.localPosition.dx / box.size.width).clamp(0.0, 1.0));
+ } : null,
+ onHorizontalDragUpdate: interactive ? (d) {
+ final box = context.findRenderObject() as RenderBox;
+ setState(() => _dragValue = (d.localPosition.dx / box.size.width).clamp(0.0, 1.0));
+ } : null,
+ onHorizontalDragEnd: interactive ? (_) {
+ if (_dragValue != null) {
+ final seekMs = (_dragValue! * totalDur * 1000).round();
+ _doSeek(seekMs);
+ }
+ setState(() => _dragValue = null);
+ _expandController.reverse();
+ } : null,
+ onLongPressStart: interactive ? (d) {
+ _expandController.forward();
+ final box = context.findRenderObject() as RenderBox;
+ setState(() => _dragValue = (d.localPosition.dx / box.size.width).clamp(0.0, 1.0));
+ } : null,
+ onLongPressMoveUpdate: interactive ? (d) {
+ final box = context.findRenderObject() as RenderBox;
+ setState(() => _dragValue = (d.localPosition.dx / box.size.width).clamp(0.0, 1.0));
+ } : null,
+ onLongPressEnd: interactive ? (_) {
+ if (_dragValue != null) {
+ final seekMs = (_dragValue! * totalDur * 1000).round();
+ _doSeek(seekMs);
+ }
+ setState(() => _dragValue = null);
+ _expandController.reverse();
+ } : null,
+ child: SizedBox(
+ height: totalHeight,
+ child: Stack(
+ children: [
+ // Progress bar
+ Positioned(
+ top: 0,
+ left: 0,
+ right: 0,
+ height: barHeight,
+ child: CustomPaint(
+ painter: EdgeProgressPainter(
+ progress: displayProgress,
+ accent: widget.accent,
+ expandProgress: expandT,
+ isDragging: _dragValue != null,
+ trackBackground: cs.onSurface.withValues(alpha: 0.08),
+ ),
+ ),
+ ),
+ // Time labels (fade in when expanded)
+ if (expandT > 0.2)
+ Positioned(
+ left: 12,
+ right: 12,
+ bottom: 2,
+ child: Opacity(
+ opacity: ((expandT - 0.2) / 0.8).clamp(0.0, 1.0),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ _fmt(_dragValue != null ? _dragValue! * totalDur / speedDiv : bookElapsed),
+ style: tt.labelSmall?.copyWith(
+ color: _dragValue != null
+ ? widget.accent
+ : cs.onSurface.withValues(alpha: 0.7),
+ fontSize: 11,
+ fontWeight: FontWeight.w600,
+ fontFeatures: const [FontFeature.tabularFigures()],
+ shadows: [Shadow(
+ color: isDark
+ ? Colors.black.withValues(alpha: 0.6)
+ : Colors.white.withValues(alpha: 0.6),
+ blurRadius: 3,
+ )],
+ ),
+ ),
+ Text(
+ '-${_fmt(_dragValue != null ? (1.0 - _dragValue!) * totalDur / speedDiv : bookRemaining)}',
+ style: tt.labelSmall?.copyWith(
+ color: _dragValue != null
+ ? widget.accent
+ : cs.onSurface.withValues(alpha: 0.6),
+ fontSize: 11,
+ fontWeight: FontWeight.w500,
+ fontFeatures: const [FontFeature.tabularFigures()],
+ shadows: [Shadow(
+ color: isDark
+ ? Colors.black.withValues(alpha: 0.6)
+ : Colors.white.withValues(alpha: 0.6),
+ blurRadius: 3,
+ )],
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ },
+ );
+ }
+}
+
+// ─── EDGE PROGRESS PAINTER ───────────────────────────────────────────
+
+class EdgeProgressPainter extends CustomPainter {
+ final double progress;
+ final Color accent;
+ final double expandProgress;
+ final bool isDragging;
+ final Color trackBackground;
+
+ EdgeProgressPainter({
+ required this.progress,
+ required this.accent,
+ required this.expandProgress,
+ required this.isDragging,
+ required this.trackBackground,
+ });
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final h = size.height;
+ final w = size.width;
+ final r = h / 2;
+
+ // Track background
+ final bgPaint = Paint()..color = trackBackground;
+ canvas.drawRRect(
+ RRect.fromLTRBR(0, 0, w, h, Radius.circular(r)),
+ bgPaint,
+ );
+
+ // Progress fill
+ if (progress > 0) {
+ final fillW = (progress * w).clamp(0.0, w);
+ final fillPaint = Paint()..color = accent.withValues(alpha: lerpDouble(0.5, 0.6, expandProgress)!);
+ canvas.drawRRect(
+ RRect.fromLTRBR(0, 0, fillW, h, Radius.circular(r)),
+ fillPaint,
+ );
+ }
+
+ // Progress edge line (glow when dragging/expanded)
+ if (progress > 0 && progress < 1) {
+ final lineX = (progress * w).clamp(r, w - r);
+ if (isDragging || expandProgress > 0.3) {
+ // Glow effect
+ final glowPaint = Paint()
+ ..color = accent.withValues(alpha: 0.2)
+ ..strokeWidth = 6
+ ..maskFilter = const MaskFilter.blur(BlurStyle.normal, 4);
+ canvas.drawLine(Offset(lineX, 0), Offset(lineX, h), glowPaint);
+ final midPaint = Paint()
+ ..color = accent.withValues(alpha: 0.5)
+ ..strokeWidth = 3
+ ..maskFilter = const MaskFilter.blur(BlurStyle.normal, 2);
+ canvas.drawLine(Offset(lineX, 0), Offset(lineX, h), midPaint);
+ }
+ final corePaint = Paint()
+ ..color = accent.withValues(alpha: lerpDouble(0.4, 0.9, expandProgress)!)
+ ..strokeWidth = lerpDouble(1.0, 1.5, expandProgress)!;
+ canvas.drawLine(Offset(lineX, 0), Offset(lineX, h), corePaint);
+ }
+
+ // Thumb (only when dragging) - positioned at bottom of bar so it hangs below
+ if (isDragging && expandProgress > 0.3) {
+ final thumbX = (progress * w).clamp(r, w - r);
+ final thumbR = lerpDouble(0.0, 6.0, ((expandProgress - 0.3) / 0.7).clamp(0.0, 1.0))!;
+ final thumbY = h;
+ if (thumbR > 0) {
+ // Shadow
+ canvas.drawCircle(
+ Offset(thumbX, thumbY + 1),
+ thumbR,
+ Paint()
+ ..color = Colors.black.withValues(alpha: 0.3)
+ ..maskFilter = const MaskFilter.blur(BlurStyle.normal, 3),
+ );
+ // Fill
+ canvas.drawCircle(Offset(thumbX, thumbY), thumbR, Paint()..color = accent);
+ // Border
+ canvas.drawCircle(
+ Offset(thumbX, thumbY),
+ thumbR,
+ Paint()
+ ..color = Colors.white.withValues(alpha: 0.9)
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = 1.5,
+ );
+ }
+ }
+ }
+
+ @override
+ bool shouldRepaint(EdgeProgressPainter old) =>
+ progress != old.progress ||
+ expandProgress != old.expandProgress ||
+ isDragging != old.isDragging ||
+ accent != old.accent;
+}
diff --git a/lib/widgets/card_playback_controls.dart b/lib/widgets/card_playback_controls.dart
index f5fef00e..ce3d6349 100644
--- a/lib/widgets/card_playback_controls.dart
+++ b/lib/widgets/card_playback_controls.dart
@@ -56,7 +56,7 @@ class _CardPlaybackControlsState extends State<CardPlaybackControls> {
final cast = ChromecastService();
return ListenableBuilder(
- listenable: cast,
+ listenable: Listenable.merge([cast, widget.player]),
builder: (context, _) {
// Check if we're casting this specific book
final castItemId = widget.itemId ?? widget.player.currentItemId;
@@ -95,28 +95,28 @@ class _CardPlaybackControlsState extends State<CardPlaybackControls> {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
- GestureDetector(
+ Flexible(child: GestureDetector(
onTap: cast.skipToPreviousChapter,
child: SizedBox(width: 52, height: 52, child: Center(
child: Icon(Icons.skip_previous_rounded, size: 34, color: cs.onSurfaceVariant),
)),
- ),
- GestureDetector(
+ )),
+ Flexible(child: GestureDetector(
onTap: () => cast.skipBackward(_backSkip),
child: SizedBox(width: 60, height: 60, child: Center(child: _skipIcon(_backSkip, false))),
- ),
+ )),
if (widget.showPlayButton)
- _playPauseButton(cs, playing: cast.isPlaying, loading: false, onTap: cast.togglePlayPause),
- GestureDetector(
+ Flexible(child: _playPauseButton(cs, playing: cast.isPlaying, loading: false, onTap: cast.togglePlayPause)),
+ Flexible(child: GestureDetector(
onTap: () => cast.skipForward(_forwardSkip),
child: SizedBox(width: 60, height: 60, child: Center(child: _skipIcon(_forwardSkip, true))),
- ),
- GestureDetector(
+ )),
+ Flexible(child: GestureDetector(
onTap: cast.skipToNextChapter,
child: SizedBox(width: 52, height: 52, child: Center(
child: Icon(Icons.skip_next_rounded, size: 34, color: cs.onSurfaceVariant),
)),
- ),
+ )),
],
);
}
@@ -124,33 +124,33 @@ class _CardPlaybackControlsState extends State<CardPlaybackControls> {
/// Original local player controls
Widget _buildLocalControls() {
final cs = Theme.of(context).colorScheme;
- final loading = widget.isStarting || (widget.isActive && widget.player.isLoadingOrBuffering);
+ final loading = widget.isStarting || (widget.isActive && widget.player.isLoadingOrBuffering && !widget.player.isPlaying);
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
- GestureDetector(
+ Flexible(child: GestureDetector(
onTap: widget.isActive ? widget.player.skipToPreviousChapter : null,
child: SizedBox(width: 52, height: 52, child: Center(
child: Icon(Icons.skip_previous_rounded, size: 34, color: widget.isActive ? cs.onSurfaceVariant : cs.onSurface.withValues(alpha: 0.12)),
)),
- ),
- GestureDetector(
+ )),
+ Flexible(child: GestureDetector(
onTap: widget.isActive ? () => widget.player.skipBackward(_backSkip) : null,
child: SizedBox(width: 60, height: 60, child: Center(child: _skipIcon(_backSkip, false, active: widget.isActive))),
- ),
+ )),
if (widget.showPlayButton)
- _playPauseButton(cs, playing: widget.isActive && widget.player.isPlaying, loading: loading,
- onTap: widget.isActive ? widget.player.togglePlayPause : widget.onStart),
- GestureDetector(
+ Flexible(child: _playPauseButton(cs, playing: widget.isActive && widget.player.isPlaying, loading: loading,
+ onTap: widget.isActive ? widget.player.togglePlayPause : widget.onStart)),
+ Flexible(child: GestureDetector(
onTap: widget.isActive ? () => widget.player.skipForward(_forwardSkip) : null,
child: SizedBox(width: 60, height: 60, child: Center(child: _skipIcon(_forwardSkip, true, active: widget.isActive))),
- ),
- GestureDetector(
+ )),
+ Flexible(child: GestureDetector(
onTap: widget.isActive ? widget.player.skipToNextChapter : null,
child: SizedBox(width: 52, height: 52, child: Center(
child: Icon(Icons.skip_next_rounded, size: 34, color: widget.isActive ? cs.onSurfaceVariant : cs.onSurface.withValues(alpha: 0.12)),
)),
- ),
+ )),
],
);
}
diff --git a/lib/widgets/expanded_card.dart b/lib/widgets/expanded_card.dart
index 79df58f3..e9fecd77 100644
--- a/lib/widgets/expanded_card.dart
+++ b/lib/widgets/expanded_card.dart
@@ -532,11 +532,14 @@ class _ExpandedCardState extends State<ExpandedCard> {
),
// Layer 3: Content
SafeArea(
- child: Column(
+ child: LayoutBuilder(
+ builder: (context, outerConstraints) {
+ final compact = outerConstraints.maxHeight < 600;
+ return Column(
children: [
// ── Stats row ──
Padding(
- padding: const EdgeInsets.fromLTRB(24, 12, 24, 0),
+ padding: EdgeInsets.fromLTRB(24, compact ? 4 : 12, 24, 0),
child: Row(
children: [
Text('${(bookProgress * 100).clamp(0, 100).toStringAsFixed(1)}%',
@@ -546,13 +549,6 @@ class _ExpandedCardState extends State<ExpandedCard> {
shadows: [Shadow(color: isDark ? Colors.black.withValues(alpha: 0.6) : Colors.white.withValues(alpha: 0.6), blurRadius: 4)],
)),
const Spacer(),
- if (totalChapters > 0 && (!_isPodcastEpisode || _chapters.isNotEmpty))
- Text('Ch ${(chapterIdx + 1).clamp(1, totalChapters)} / $totalChapters',
- style: tt.labelMedium?.copyWith(
- color: isDark ? Colors.white.withValues(alpha: 0.85) : Colors.black.withValues(alpha: 0.75),
- fontWeight: FontWeight.w700, fontSize: 15,
- shadows: [Shadow(color: isDark ? Colors.black.withValues(alpha: 0.6) : Colors.white.withValues(alpha: 0.6), blurRadius: 4)],
- )),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: _dismissExpanded,
@@ -570,9 +566,9 @@ class _ExpandedCardState extends State<ExpandedCard> {
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CardDualProgressBar(player: widget.player, accent: accent, isActive: _isActive, staticProgress: progress, staticDuration: _effectiveDuration, chapters: _chapters, showBookBar: (!_isPodcastEpisode || _chapters.isNotEmpty) && (!lib.isPodcastLibrary || _chapters.isNotEmpty), showChapterBar: false, itemId: _itemId),
),
- const SizedBox(height: 16),
+ SizedBox(height: compact ? 4 : 16),
// ── Cover art (larger — 90% width) ──
- Flexible(
+ Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: ListenableBuilder(
@@ -606,7 +602,7 @@ class _ExpandedCardState extends State<ExpandedCard> {
} else {
_startPlayback();
}
- } : _dismissExpanded,
+ } : null,
child: Container(
width: coverW,
height: coverH,
@@ -734,20 +730,23 @@ class _ExpandedCardState extends State<ExpandedCard> {
),
),
),
- const SizedBox(height: 24),
+ SizedBox(height: compact ? 6 : 24),
// ── Chapter scrubber ──
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CardDualProgressBar(player: widget.player, accent: accent, isActive: _isActive, staticProgress: (_isPodcastEpisode && _chapters.isEmpty) ? 0.0 : progress, staticDuration: (_isPodcastEpisode && _chapters.isEmpty) ? widget.player.totalDuration : _effectiveDuration, chapters: _chapters, showBookBar: false, showChapterBar: true, chapterName: (_isPodcastEpisode && _chapters.isEmpty) ? (widget.player.currentEpisodeTitle ?? widget.player.currentTitle ?? _title) : (_episodeId != null && !_isActive ? (_recentEpisode?['title'] as String? ?? _title) : _chapterName(chapterIdx)), chapterIndex: chapterIdx, totalChapters: totalChapters, itemId: _itemId),
),
// ── Controls + buttons ──
- Expanded(
+ MediaQuery(
+ data: MediaQuery.of(context).copyWith(
+ textScaler: TextScaler.noScaling,
+ ),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 28),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
- const SizedBox(height: 18),
+ SizedBox(height: compact ? 4 : 18),
CardPlaybackControls(
player: widget.player,
accent: accent,
@@ -757,10 +756,10 @@ class _ExpandedCardState extends State<ExpandedCard> {
itemId: _itemId,
showPlayButton: !_coverPlayButton,
),
- const SizedBox(height: 24),
+ SizedBox(height: compact ? 8 : 24),
// ── Button grid ──
..._buildButtonGrid(accent, tt),
- const SizedBox(height: 14),
+ SizedBox(height: compact ? 4 : 14),
// More menu / Cast controls
Center(
child: ListenableBuilder(
@@ -795,13 +794,14 @@ class _ExpandedCardState extends State<ExpandedCard> {
},
),
),
- const SizedBox(height: 12),
+ SizedBox(height: compact ? 4 : 12),
],
),
),
),
],
- ),
+ );
+ }),
),
],
),
@@ -990,7 +990,7 @@ class _ExpandedCardState extends State<ExpandedCard> {
}
Widget _buildCardButton(String id, Color accent, TextTheme tt, {bool compact = false, bool short = false}) {
- const large = true;
+ final large = MediaQuery.sizeOf(context).height > 700;
switch (id) {
case 'chapters':
return CardWideButton(
@@ -1302,7 +1302,7 @@ class _ExpandedCardState extends State<ExpandedCard> {
child: Column(children: [
Padding(padding: const EdgeInsets.symmetric(vertical: 12),
child: Container(width: 40, height: 4, decoration: BoxDecoration(color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.24), borderRadius: BorderRadius.circular(2)))),
- Text('Chapters', style: tt.titleMedium?.copyWith(fontWeight: FontWeight.w600)),
+ Text('Chapters (${chapters.length})', style: tt.titleMedium?.copyWith(fontWeight: FontWeight.w600)),
const SizedBox(height: 8),
Expanded(child: ListView.builder(
controller: sc, itemCount: chapters.length,