Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix sheets safe area, sub-series animation, misc fixes

Nathan Poulson18e680ea19b7
diff --git a/lib/screens/app_shell.dart b/lib/screens/app_shell.dart
index 458a4fb0..e4293a9c 100644
--- a/lib/screens/app_shell.dart
+++ b/lib/screens/app_shell.dart
@@ -485,10 +485,18 @@ class _AppShellState extends State<AppShell> with WidgetsBindingObserver, Ticker
}
Widget _buildBottomNav(BuildContext context) {
- // Lazily attach listener when on Home or Library tab (handles start-on-tab case)
+ // Lazily attach listener when on Home or Library tab (handles start-on-tab case).
+ // The screen's state may not exist on the first frame, so retry until attached.
if ((_currentIndex == 0 || _currentIndex == 1) && _navBarListener == null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
- if (mounted) _syncNavBarListener(_currentIndex);
+ if (!mounted) return;
+ _syncNavBarListener(_currentIndex);
+ // If the screen state wasn't ready yet, retry on next frame
+ if (_navBarListener == null && (_currentIndex == 0 || _currentIndex == 1)) {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted) _syncNavBarListener(_currentIndex);
+ });
+ }
});
}
return SizeTransition(
diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart
index 94d698ab..827bc901 100644
--- a/lib/screens/home_screen.dart
+++ b/lib/screens/home_screen.dart
@@ -26,20 +26,17 @@ class HomeScreen extends StatefulWidget {
State<HomeScreen> createState() => HomeScreenState();
}
-class HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
+class HomeScreenState extends State<HomeScreen> {
final _player = AudioPlayerService();
bool _hideEbookOnly = false;
bool _rectangleCovers = false;
// ── Scroll-to-hide bars ──
final ValueNotifier<bool> barsVisibleNotifier = ValueNotifier(true);
- late final AnimationController _headerAnimController = AnimationController(
- vsync: this,
- duration: const Duration(milliseconds: 250),
- value: 1.0,
- );
final _scrollController = ScrollController();
double _lastScrollOffset = 0;
+ double _scrollAccumulator = 0;
+ static const _scrollThreshold = 40.0;
// Cached filtered sections — invalidated when source data or settings change.
List<Map<String, dynamic>>? _cachedSections;
@@ -61,22 +58,33 @@ class HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
final offset = _scrollController.offset;
final delta = offset - _lastScrollOffset;
_lastScrollOffset = offset;
- if (offset <= 0) { _showBars(); return; }
- if (delta.abs() < 1.0) return;
- if (delta > 0) { _hideBars(); } else { _showBars(); }
+
+ if (offset <= 0) {
+ _scrollAccumulator = 0;
+ _showBars();
+ return;
+ }
+ if (delta.abs() < 0.5) return;
+
+ if ((delta > 0) != (_scrollAccumulator > 0)) _scrollAccumulator = 0;
+ _scrollAccumulator += delta;
+
+ if (_scrollAccumulator > _scrollThreshold) {
+ _hideBars();
+ } else if (_scrollAccumulator < -_scrollThreshold) {
+ _showBars();
+ }
}
void _showBars() {
if (!barsVisibleNotifier.value) {
barsVisibleNotifier.value = true;
- _headerAnimController.forward();
}
}
void _hideBars() {
if (barsVisibleNotifier.value) {
barsVisibleNotifier.value = false;
- _headerAnimController.reverse();
}
}
@@ -175,7 +183,6 @@ class HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
@override
void dispose() {
_scrollController.dispose();
- _headerAnimController.dispose();
barsVisibleNotifier.dispose();
_player.removeListener(_onPlayerChanged);
PlayerSettings.settingsChanged.removeListener(_loadSettings);
@@ -352,10 +359,7 @@ class HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
slivers: [
// ── Top bar: ABSORB title + page name ──
SliverToBoxAdapter(
- child: SizeTransition(
- sizeFactor: _headerAnimController,
- axisAlignment: -1.0,
- child: AbsorbPageHeader(
+ child: AbsorbPageHeader(
title: 'Home',
trailing: GestureDetector(
onTap: () {
@@ -445,7 +449,6 @@ class HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
),
],
),
- ),
),
// (Continue Listening is now rendered in the generic sections loop below)
@@ -627,14 +630,18 @@ class HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
);
} else {
sectionIcon = _sectionIcons[id] ?? Icons.album_outlined;
- final sectionLabel = label as String;
- titleTap = () => SectionDetailSheet.show(
- context,
- title: sectionLabel,
- icon: sectionIcon,
- entities: entities,
- coverAspectRatio: _rectangleCovers ? 2 / 3 : 1.0,
- );
+ // Author/series sections don't have book-shaped entities,
+ // so skip the book-oriented SectionDetailSheet for them.
+ if (type != 'authors' && type != 'series') {
+ final sectionLabel = label as String;
+ titleTap = () => SectionDetailSheet.show(
+ context,
+ title: sectionLabel,
+ icon: sectionIcon,
+ entities: entities,
+ coverAspectRatio: _rectangleCovers ? 2 / 3 : 1.0,
+ );
+ }
}
return <Widget>[
diff --git a/lib/screens/library_screen.dart b/lib/screens/library_screen.dart
index 64db0482..e3c00e5f 100644
--- a/lib/screens/library_screen.dart
+++ b/lib/screens/library_screen.dart
@@ -116,10 +116,12 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
final ValueNotifier<bool> barsVisibleNotifier = ValueNotifier(true);
late final AnimationController _headerAnimController = AnimationController(
vsync: this,
- duration: const Duration(milliseconds: 250),
+ duration: const Duration(milliseconds: 400),
value: 1.0,
);
double _lastScrollOffset = 0;
+ double _scrollAccumulator = 0;
+ static const _scrollThreshold = 40.0; // pixels of scroll before hide/show triggers
void _onScrollDirection(ScrollController controller) {
if (_isInSearchMode) return;
@@ -130,15 +132,19 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
// At the top, always show
if (offset <= 0) {
+ _scrollAccumulator = 0;
_showBars();
return;
}
- // Ignore tiny deltas (noise from overscroll bounce etc.)
- if (delta.abs() < 1.0) return;
+ if (delta.abs() < 0.5) return;
- if (delta > 0) {
+ // Accumulate scroll in current direction; reset on direction change
+ if ((delta > 0) != (_scrollAccumulator > 0)) _scrollAccumulator = 0;
+ _scrollAccumulator += delta;
+
+ if (_scrollAccumulator > _scrollThreshold) {
_hideBars();
- } else if (delta < 0) {
+ } else if (_scrollAccumulator < -_scrollThreshold) {
_showBars();
}
}
@@ -1191,168 +1197,163 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
),
),
SafeArea(
- child: Column(
- children: [
- SizeTransition(
- sizeFactor: _headerAnimController,
- axisAlignment: -1.0,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- AbsorbPageHeader(
- title: 'Library',
- trailing: GestureDetector(
- onTap: () {
- final newVal = !lib.isManualOffline;
- lib.setManualOffline(newVal);
- if (newVal) {
- final dl = DownloadService();
- final player = AudioPlayerService();
- final itemId = player.currentItemId;
- final epId = player.currentEpisodeId;
- final dlKey = epId != null && itemId != null
- ? '$itemId-$epId'
- : itemId;
- if (dlKey == null || !dl.isDownloaded(dlKey)) {
- player.stop();
- }
+ child: Column(
+ children: [
+ SizeTransition(
+ sizeFactor: _headerAnimController,
+ axisAlignment: -1.0,
+ child: Column(mainAxisSize: MainAxisSize.min, children: [
+ AbsorbPageHeader(
+ title: 'Library',
+ trailing: GestureDetector(
+ onTap: () {
+ final newVal = !lib.isManualOffline;
+ lib.setManualOffline(newVal);
+ if (newVal) {
+ final dl = DownloadService();
+ final player = AudioPlayerService();
+ final itemId = player.currentItemId;
+ final epId = player.currentEpisodeId;
+ final dlKey = epId != null && itemId != null
+ ? '$itemId-$epId'
+ : itemId;
+ if (dlKey == null || !dl.isDownloaded(dlKey)) {
+ player.stop();
}
- },
- child: Icon(
- lib.isOffline ? Icons.cloud_off_rounded : Icons.cloud_done_rounded,
- size: 20, color: lib.isOffline ? Colors.orange : Colors.green,
- ),
+ }
+ },
+ child: Icon(
+ lib.isOffline ? Icons.cloud_off_rounded : Icons.cloud_done_rounded,
+ size: 20, color: lib.isOffline ? Colors.orange : Colors.green,
),
- actions: hasMultipleLibraries ? [
- GestureDetector(
- onTap: () => _showLibraryPicker(context, cs, tt, allLibraries, lib),
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
- decoration: BoxDecoration(
- color: cs.onSurface.withValues(alpha: 0.06),
- borderRadius: BorderRadius.circular(20),
- border: Border.all(color: cs.onSurface.withValues(alpha: 0.08)),
- ),
- child: SizedBox(
- height: 20,
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(lib.isPodcastLibrary ? Icons.podcasts_rounded : Icons.auto_stories_rounded, size: 18, color: cs.onSurfaceVariant),
- const SizedBox(width: 6),
- ConstrainedBox(
- constraints: const BoxConstraints(maxWidth: 140),
- child: Text(libraryName, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: cs.onSurfaceVariant),
- overflow: TextOverflow.ellipsis, maxLines: 1),
- ),
- const SizedBox(width: 4),
- Icon(Icons.unfold_more_rounded, size: 18, color: cs.onSurfaceVariant),
- ],
- ),
- ),
- ),
- ),
- ] : null,
),
- Padding(
- padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
- child: SearchBar(
- controller: _searchController,
- focusNode: _focusNode,
- hintText: lib.isPodcastLibrary
- ? 'Search shows and episodes...'
- : 'Search books, series, and authors...',
- leading: const Padding(
- padding: EdgeInsets.only(left: 8),
- child: Icon(Icons.search_rounded),
- ),
- trailing: [
- if (_searchController.text.isNotEmpty)
- IconButton(
- icon: const Icon(Icons.clear_rounded),
- onPressed: () {
- _searchController.clear();
- _onSearchChanged('');
- _focusNode.unfocus();
- },
+ actions: hasMultipleLibraries ? [
+ GestureDetector(
+ onTap: () => _showLibraryPicker(context, cs, tt, allLibraries, lib),
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
+ decoration: BoxDecoration(
+ color: cs.onSurface.withValues(alpha: 0.06),
+ borderRadius: BorderRadius.circular(20),
+ border: Border.all(color: cs.onSurface.withValues(alpha: 0.08)),
+ ),
+ child: SizedBox(
+ height: 20,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(lib.isPodcastLibrary ? Icons.podcasts_rounded : Icons.auto_stories_rounded, size: 18, color: cs.onSurfaceVariant),
+ const SizedBox(width: 6),
+ ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 140),
+ child: Text(libraryName, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: cs.onSurfaceVariant),
+ overflow: TextOverflow.ellipsis, maxLines: 1),
+ ),
+ const SizedBox(width: 4),
+ Icon(Icons.unfold_more_rounded, size: 18, color: cs.onSurfaceVariant),
+ ],
),
- ],
- onChanged: _onSearchChanged,
- padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(horizontal: 8)),
- side: WidgetStatePropertyAll(
- BorderSide(color: cs.onSurface.withValues(alpha: 0.08)),
+ ),
),
),
+ ] : null,
+ ),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
+ child: SearchBar(
+ controller: _searchController,
+ focusNode: _focusNode,
+ hintText: lib.isPodcastLibrary
+ ? 'Search shows and episodes...'
+ : 'Search books, series, and authors...',
+ leading: const Padding(
+ padding: EdgeInsets.only(left: 8),
+ child: Icon(Icons.search_rounded),
+ ),
+ trailing: [
+ if (_searchController.text.isNotEmpty)
+ IconButton(
+ icon: const Icon(Icons.clear_rounded),
+ onPressed: () {
+ _searchController.clear();
+ _onSearchChanged('');
+ _focusNode.unfocus();
+ },
+ ),
+ ],
+ onChanged: _onSearchChanged,
+ padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(horizontal: 8)),
+ side: WidgetStatePropertyAll(
+ BorderSide(color: cs.onSurface.withValues(alpha: 0.08)),
+ ),
),
-
- // Item count + filter badge row
- if (!_isInSearchMode)
- _buildInfoRow(cs, tt),
- ],
- ),
- ),
-
- Expanded(
- child: Stack(
- children: [
- _isInSearchMode
- ? _buildSearchResults(cs, tt)
- : hasTabs
- ? _buildTabbedContent(cs, tt)
- : _buildGrid(),
- // Floating tab bar at bottom (book libraries only, hidden during search)
- if (hasTabs)
- Positioned(
- left: 0, right: 0,
- bottom: 12,
- child: ValueListenableBuilder<bool>(
- valueListenable: barsVisibleNotifier,
- builder: (_, visible, child) => AnimatedSlide(
- duration: const Duration(milliseconds: 250),
- offset: visible ? Offset.zero : const Offset(0, 3),
- child: AnimatedOpacity(
- duration: const Duration(milliseconds: 200),
- opacity: visible ? 1.0 : 0.0,
- child: child,
+ ),
+ // Item count + filter badge row
+ if (!_isInSearchMode)
+ _buildInfoRow(cs, tt),
+ ]),
+ ),
+ Expanded(
+ child: Stack(
+ children: [
+ _isInSearchMode
+ ? _buildSearchResults(cs, tt)
+ : hasTabs
+ ? _buildTabbedContent(cs, tt)
+ : _buildGrid(),
+ // Floating tab bar at bottom (book libraries only, hidden during search)
+ if (hasTabs)
+ Positioned(
+ left: 0, right: 0,
+ bottom: 12,
+ child: ValueListenableBuilder<bool>(
+ valueListenable: barsVisibleNotifier,
+ builder: (_, visible, child) => AnimatedSlide(
+ duration: const Duration(milliseconds: 250),
+ offset: visible ? Offset.zero : const Offset(0, 3),
+ child: AnimatedOpacity(
+ duration: const Duration(milliseconds: 200),
+ opacity: visible ? 1.0 : 0.0,
+ child: child,
+ ),
+ ),
+ child: _buildFloatingTabBar(cs),
),
),
- child: _buildFloatingTabBar(cs),
- ),
- ),
- // Floating sort button for podcast libraries
- if (!hasTabs && !_isInSearchMode)
- Positioned(
- left: 0, right: 0,
- bottom: 12,
- child: ValueListenableBuilder<bool>(
- valueListenable: barsVisibleNotifier,
- builder: (_, visible, child) => AnimatedSlide(
- duration: const Duration(milliseconds: 250),
- offset: visible ? Offset.zero : const Offset(0, 3),
- child: AnimatedOpacity(
- duration: const Duration(milliseconds: 200),
- opacity: visible ? 1.0 : 0.0,
- child: child,
+ // Floating sort button for podcast libraries
+ if (!hasTabs && !_isInSearchMode)
+ Positioned(
+ left: 0, right: 0,
+ bottom: 12,
+ child: ValueListenableBuilder<bool>(
+ valueListenable: barsVisibleNotifier,
+ builder: (_, visible, child) => AnimatedSlide(
+ duration: const Duration(milliseconds: 250),
+ offset: visible ? Offset.zero : const Offset(0, 3),
+ child: AnimatedOpacity(
+ duration: const Duration(milliseconds: 200),
+ opacity: visible ? 1.0 : 0.0,
+ child: child,
+ ),
+ ),
+ child: Center(child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ _buildFloatingSortButton(cs, tt),
+ if (context.read<AuthProvider>().isRoot) ...[
+ const SizedBox(width: 8),
+ _buildFloatingManageButton(cs),
+ ],
+ ],
+ )),
),
),
- child: Center(child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- _buildFloatingSortButton(cs, tt),
- if (context.read<AuthProvider>().isRoot) ...[
- const SizedBox(width: 8),
- _buildFloatingManageButton(cs),
- ],
- ],
- )),
- ),
- ),
- ],
- ),
+ ],
+ ),
+ ),
+ ],
),
- ],
- ),
- ),
+ ),
],
),
);
diff --git a/lib/widgets/home_customize_sheet.dart b/lib/widgets/home_customize_sheet.dart
index b6ac17ed..591d0d18 100644
--- a/lib/widgets/home_customize_sheet.dart
+++ b/lib/widgets/home_customize_sheet.dart
@@ -142,7 +142,7 @@ class _HomeCustomizeSheetState extends State<HomeCustomizeSheet> {
? Center(child: Text('No genres found', style: tt.bodyMedium?.copyWith(color: cs.onSurfaceVariant)))
: ListView.builder(
controller: sc,
- padding: const EdgeInsets.symmetric(vertical: 8),
+ padding: EdgeInsets.only(top: 8, bottom: MediaQuery.of(ctx).padding.bottom + 8),
itemCount: genres.length,
itemBuilder: (ctx, i) {
final genre = genres[i];
@@ -265,7 +265,7 @@ class _HomeCustomizeSheetState extends State<HomeCustomizeSheet> {
Expanded(
child: ReorderableListView.builder(
scrollController: widget.scrollController,
- padding: const EdgeInsets.symmetric(vertical: 8),
+ padding: EdgeInsets.only(top: 8, bottom: MediaQuery.of(context).padding.bottom + 8),
itemCount: _sections.length,
onReorderStart: (_) => HapticFeedback.mediumImpact(),
onReorder: (oldIndex, newIndex) {
diff --git a/lib/widgets/series_books_sheet.dart b/lib/widgets/series_books_sheet.dart
index 0adf0e89..6a41a9ba 100644
--- a/lib/widgets/series_books_sheet.dart
+++ b/lib/widgets/series_books_sheet.dart
@@ -409,39 +409,48 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {
final numBooks = series['numBooks'] as int? ?? subBooks.length;
final isExpanded = _expandedSubSeries.contains(seriesId);
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- GestureDetector(
- onTap: () => setState(() {
- if (isExpanded) _expandedSubSeries.remove(seriesId);
- else _expandedSubSeries.add(seriesId);
- }),
- onLongPress: seriesId.isNotEmpty ? () {
- showSeriesBooksSheet(context,
- seriesName: seriesName, seriesId: seriesId,
- serverUrl: widget.serverUrl, token: widget.token, libraryId: widget.libraryId,
- parentSeriesId: widget.seriesId);
- } : null,
- child: Container(
- margin: const EdgeInsets.only(bottom: 8, top: 4),
- padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
- decoration: BoxDecoration(color: cs.surfaceContainerHigh, borderRadius: BorderRadius.circular(12)),
- child: Row(children: [
- Icon(isExpanded ? Icons.expand_less_rounded : Icons.expand_more_rounded, size: 20, color: cs.onSurfaceVariant),
- const SizedBox(width: 8),
- Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
- Text(seriesName, style: tt.bodyMedium?.copyWith(fontWeight: FontWeight.w600, color: cs.onSurface)),
- const SizedBox(height: 2),
- Text('$numBooks book${numBooks != 1 ? 's' : ''}',
- style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant.withValues(alpha: 0.5), fontSize: 11)),
- ])),
- ]),
+ return AnimatedSize(
+ duration: const Duration(milliseconds: 250),
+ curve: Curves.easeInOut,
+ alignment: Alignment.topCenter,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ GestureDetector(
+ onTap: () => setState(() {
+ if (isExpanded) _expandedSubSeries.remove(seriesId);
+ else _expandedSubSeries.add(seriesId);
+ }),
+ onLongPress: seriesId.isNotEmpty ? () {
+ showSeriesBooksSheet(context,
+ seriesName: seriesName, seriesId: seriesId,
+ serverUrl: widget.serverUrl, token: widget.token, libraryId: widget.libraryId,
+ parentSeriesId: widget.seriesId);
+ } : null,
+ child: Container(
+ margin: const EdgeInsets.only(bottom: 8, top: 4),
+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
+ decoration: BoxDecoration(color: cs.surfaceContainerHigh, borderRadius: BorderRadius.circular(12)),
+ child: Row(children: [
+ AnimatedRotation(
+ turns: isExpanded ? 0.5 : 0.0,
+ duration: const Duration(milliseconds: 250),
+ child: Icon(Icons.expand_more_rounded, size: 20, color: cs.onSurfaceVariant),
+ ),
+ const SizedBox(width: 8),
+ Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(seriesName, style: tt.bodyMedium?.copyWith(fontWeight: FontWeight.w600, color: cs.onSurface)),
+ const SizedBox(height: 2),
+ Text('$numBooks book${numBooks != 1 ? 's' : ''}',
+ style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant.withValues(alpha: 0.5), fontSize: 11)),
+ ])),
+ ]),
+ ),
),
- ),
- if (isExpanded)
- ...subBooks.map((book) => _buildBookCard(cs, tt, lib, book)),
- ],
+ if (isExpanded)
+ ...subBooks.map((book) => _buildBookCard(cs, tt, lib, book)),
+ ],
+ ),
);
}(),
],
@@ -619,7 +628,7 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {
decoration: BoxDecoration(color: cs.onSurface.withValues(alpha: 0.24), borderRadius: BorderRadius.circular(2)))),
if (!allDownloaded)
_moreItem(cs, Icons.download_rounded,
- downloaded > 0 ? 'Download Remaining (${_books.length - downloaded})' : 'Download All',
+ downloaded > 0 ? 'Download Remaining (${(_totalBooks > 0 ? _totalBooks : _books.length) - downloaded})' : 'Download All',
onTap: () { Navigator.pop(ctx); _downloadAll(); }),
_moreItem(cs,
allDone ? Icons.remove_done_rounded : Icons.done_all_rounded,