A cross platform Audiobookshelf client for Android and iOS
Dart
Replace hidden SnackBars with overlay toasts in sheets
Nathan Poulson526781a64dbf
diff --git a/lib/widgets/author_books_sheet.dart b/lib/widgets/author_books_sheet.dartindex 22ba523a..850bc8d5 100644--- a/lib/widgets/author_books_sheet.dart+++ b/lib/widgets/author_books_sheet.dart@@ -1,5 +1,7 @@import 'package:flutter/material.dart';+import 'package:flutter/services.dart';import 'package:cached_network_image/cached_network_image.dart';+import 'overlay_toast.dart';import 'package:provider/provider.dart';import '../providers/auth_provider.dart';import '../providers/library_provider.dart';@@ -497,13 +499,9 @@ class _AuthorBooksSheetState extends State<AuthorBooksSheet> {confirmDismiss: (_) async {await lib.addToAbsorbingQueue(bookId);lib.absorbingItemCache[bookId] = Map<String, dynamic>.from(book);+ HapticFeedback.mediumImpact();if (context.mounted) {- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- content: Text('Added "$bookTitle" to Absorbing'),- behavior: SnackBarBehavior.floating,- duration: const Duration(seconds: 2),- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),- ));+ showOverlayToast(context, 'Added "$bookTitle" to Absorbing', icon: Icons.add_circle_outline_rounded);}return false;},diff --git a/lib/widgets/book_detail_sheet.dart b/lib/widgets/book_detail_sheet.dartindex aa612bda..83e67bcc 100644--- a/lib/widgets/book_detail_sheet.dart+++ b/lib/widgets/book_detail_sheet.dart@@ -4,7 +4,9 @@ import 'dart:ui' as ui;import 'package:flutter/foundation.dart';import 'package:flutter/gestures.dart';import 'package:flutter/material.dart';+import 'package:flutter/services.dart';import 'package:provider/provider.dart';+import 'overlay_toast.dart';import 'package:cached_network_image/cached_network_image.dart';import 'package:path_provider/path_provider.dart';import 'package:file_picker/file_picker.dart';@@ -550,12 +552,9 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {Navigator.pop(ctx);if (lib.isOnAbsorbingList(widget.itemId)) {await lib.removeFromAbsorbing(widget.itemId);+ HapticFeedback.mediumImpact();if (context.mounted) {- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- duration: const Duration(seconds: 3),- content: const Text('Removed from Absorbing'),- behavior: SnackBarBehavior.floating,- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))));+ showOverlayToast(context, 'Removed from Absorbing', icon: Icons.remove_circle_outline_rounded);}} else {await lib.addToAbsorbingQueue(widget.itemId);@@ -564,12 +563,9 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {cached['_absorbingKey'] = widget.itemId;lib.absorbingItemCache[widget.itemId] = cached;}+ HapticFeedback.mediumImpact();if (context.mounted) {- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- duration: const Duration(seconds: 3),- content: const Text('Added to Absorbing'),- behavior: SnackBarBehavior.floating,- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))));+ showOverlayToast(context, 'Added to Absorbing', icon: Icons.add_circle_outline_rounded);}}}),@@ -1048,15 +1044,13 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {await lib.removeFromAbsorbing(widget.itemId);if (mounted) setState(() {});if (context.mounted) {- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- duration: const Duration(seconds: 3), content: const Text('Marked as finished — nice work!'),- behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))));+ showOverlayToast(context, 'Marked as finished - nice work!', icon: Icons.check_circle_rounded);}}} catch (_) {- if (context.mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(- duration: const Duration(seconds: 3), content: const Text('Failed to update — check your connection'),- behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))));+ if (context.mounted) {+ showOverlayToast(context, 'Failed to update - check your connection', icon: Icons.error_outline_rounded);+ }}}@@ -1085,14 +1079,12 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {await _loadItem();await lib.refresh();if (mounted) setState(() {});- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- duration: const Duration(seconds: 3), content: const Text('Marked as not finished — back at it!'),- behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))));+ showOverlayToast(context, 'Marked as not finished - back at it!', icon: Icons.replay_rounded);}} catch (_) {- if (context.mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(- duration: const Duration(seconds: 3), content: const Text('Failed to update — check your connection'),- behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))));+ if (context.mounted) {+ showOverlayToast(context, 'Failed to update - check your connection', icon: Icons.error_outline_rounded);+ }}}@@ -1131,10 +1123,11 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {if (context.mounted) {await _loadItem();await context.read<LibraryProvider>().refresh();- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- duration: const Duration(seconds: 3),- content: Text(serverSuccess ? 'Progress reset — fresh start!' : 'Reset may not have synced — check your server'),- behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))));+ showOverlayToast(+ context,+ serverSuccess ? 'Progress reset - fresh start!' : 'Reset may not have synced - check your server',+ icon: serverSuccess ? Icons.restart_alt_rounded : Icons.warning_amber_rounded,+ );}}diff --git a/lib/widgets/collection_detail_sheet.dart b/lib/widgets/collection_detail_sheet.dartindex 97780cba..a0e9f144 100644--- a/lib/widgets/collection_detail_sheet.dart+++ b/lib/widgets/collection_detail_sheet.dart@@ -2,6 +2,7 @@ import 'dart:io';import 'package:flutter/material.dart';import 'package:flutter/services.dart';import 'package:provider/provider.dart';+import 'overlay_toast.dart';import 'package:cached_network_image/cached_network_image.dart';import '../providers/auth_provider.dart';import '../providers/library_provider.dart';@@ -393,13 +394,9 @@ class _CollectionDetailSheetState extends State<CollectionDetailSheet> {confirmDismiss: (_) async {await lib.addToAbsorbingQueue(itemId);lib.absorbingItemCache[itemId] = Map<String, dynamic>.from(book);+ HapticFeedback.mediumImpact();if (context.mounted) {- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- content: Text('Added "$title" to Absorbing'),- behavior: SnackBarBehavior.floating,- duration: const Duration(seconds: 2),- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),- ));+ showOverlayToast(context, 'Added "$title" to Absorbing', icon: Icons.add_circle_outline_rounded);}return false;},@@ -423,13 +420,9 @@ class _CollectionDetailSheetState extends State<CollectionDetailSheet> {if (direction == DismissDirection.startToEnd) {await lib.addToAbsorbingQueue(itemId);lib.absorbingItemCache[itemId] = Map<String, dynamic>.from(book);+ HapticFeedback.mediumImpact();if (context.mounted) {- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- content: Text('Added "$title" to Absorbing'),- behavior: SnackBarBehavior.floating,- duration: const Duration(seconds: 2),- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),- ));+ showOverlayToast(context, 'Added "$title" to Absorbing', icon: Icons.add_circle_outline_rounded);}return false;}diff --git a/lib/widgets/episode_list_sheet.dart b/lib/widgets/episode_list_sheet.dartindex 9a4162a4..31c7c598 100644--- a/lib/widgets/episode_list_sheet.dart+++ b/lib/widgets/episode_list_sheet.dart@@ -1,5 +1,7 @@import 'dart:ui';import 'package:flutter/material.dart';+import 'package:flutter/services.dart';+import 'overlay_toast.dart';import 'package:shared_preferences/shared_preferences.dart';import 'package:provider/provider.dart';import 'package:cached_network_image/cached_network_image.dart';@@ -753,13 +755,9 @@ class _EpisodeListSheetState extends State<EpisodeListSheet> {cached['recentEpisode'] = Map<String, dynamic>.from(ep);cached['_absorbingKey'] = absorbKey;lib.absorbingItemCache[absorbKey] = cached;+ HapticFeedback.mediumImpact();if (context.mounted) {- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- content: Text('Added "$epTitle" to Absorbing'),- behavior: SnackBarBehavior.floating,- duration: const Duration(seconds: 2),- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),- ));+ showOverlayToast(context, 'Added "$epTitle" to Absorbing', icon: Icons.add_circle_outline_rounded);}return false;},diff --git a/lib/widgets/overlay_toast.dart b/lib/widgets/overlay_toast.dartnew file mode 100644index 00000000..3680962e--- /dev/null+++ b/lib/widgets/overlay_toast.dart@@ -0,0 +1,117 @@+import 'dart:ui' as ui;+import 'package:flutter/material.dart';++OverlayEntry? _currentToast;++/// Show a styled toast that renders above modal sheets and overlays.+///+/// Pass [icon] for a leading icon (e.g. Icons.check_circle_rounded).+void showOverlayToast(BuildContext context, String message, {IconData? icon}) {+ _currentToast?.remove();+ _currentToast = null;++ final overlay = Overlay.of(context);+ late OverlayEntry entry;+ entry = OverlayEntry(+ builder: (_) => _AnimatedToast(+ message: message,+ icon: icon,+ onDone: () {+ entry.remove();+ if (_currentToast == entry) _currentToast = null;+ },+ ),+ );+ _currentToast = entry;+ overlay.insert(entry);+}++class _AnimatedToast extends StatefulWidget {+ final String message;+ final IconData? icon;+ final VoidCallback onDone;++ const _AnimatedToast({required this.message, this.icon, required this.onDone});++ @override+ State<_AnimatedToast> createState() => _AnimatedToastState();+}++class _AnimatedToastState extends State<_AnimatedToast>+ with SingleTickerProviderStateMixin {+ late final AnimationController _controller;++ @override+ void initState() {+ super.initState();+ _controller = AnimationController(+ duration: const Duration(milliseconds: 250),+ vsync: this,+ )..forward();++ Future.delayed(const Duration(seconds: 2), () {+ if (mounted) _controller.reverse().then((_) => widget.onDone());+ });+ }++ @override+ void dispose() {+ _controller.dispose();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ final cs = Theme.of(context).colorScheme;+ return Positioned(+ bottom: MediaQuery.of(context).viewInsets.bottom + 100,+ left: 32,+ right: 32,+ child: FadeTransition(+ opacity: _controller,+ child: SlideTransition(+ position: Tween<Offset>(+ begin: const Offset(0, 0.3),+ end: Offset.zero,+ ).animate(CurvedAnimation(parent: _controller, curve: Curves.easeOut)),+ child: Center(+ child: ClipRRect(+ borderRadius: BorderRadius.circular(24),+ child: BackdropFilter(+ filter: ui.ImageFilter.blur(sigmaX: 20, sigmaY: 20),+ child: Container(+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),+ decoration: BoxDecoration(+ color: cs.surface.withValues(alpha: 0.7),+ borderRadius: BorderRadius.circular(24),+ border: Border.all(color: cs.primary.withValues(alpha: 0.25)),+ ),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ if (widget.icon != null) ...[+ Icon(widget.icon, size: 18, color: cs.primary),+ const SizedBox(width: 8),+ ],+ Flexible(+ child: Text(+ widget.message,+ style: TextStyle(+ color: cs.onSurface,+ fontSize: 13,+ fontWeight: FontWeight.w500,+ decoration: TextDecoration.none,+ ),+ ),+ ),+ ],+ ),+ ),+ ),+ ),+ ),+ ),+ ),+ );+ }+}diff --git a/lib/widgets/playlist_detail_sheet.dart b/lib/widgets/playlist_detail_sheet.dartindex bf7fca33..7d63fb43 100644--- a/lib/widgets/playlist_detail_sheet.dart+++ b/lib/widgets/playlist_detail_sheet.dart@@ -2,6 +2,7 @@ import 'dart:io';import 'package:flutter/material.dart';import 'package:flutter/services.dart';import 'package:provider/provider.dart';+import 'overlay_toast.dart';import 'package:cached_network_image/cached_network_image.dart';import '../providers/auth_provider.dart';import '../providers/library_provider.dart';@@ -574,13 +575,9 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {if (isOnAbsorbing) return false;await lib.addToAbsorbingQueue(progressKey);lib.absorbingItemCache[progressKey] = Map<String, dynamic>.from(libraryItem);+ HapticFeedback.mediumImpact();if (context.mounted) {- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- content: Text('Added "${episodeTitle ?? title}" to Absorbing'),- behavior: SnackBarBehavior.floating,- duration: const Duration(seconds: 2),- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),- ));+ showOverlayToast(context, 'Added "${episodeTitle ?? title}" to Absorbing', icon: Icons.add_circle_outline_rounded);}return false;}diff --git a/lib/widgets/series_books_sheet.dart b/lib/widgets/series_books_sheet.dartindex 08c427a9..1da7023e 100644--- a/lib/widgets/series_books_sheet.dart+++ b/lib/widgets/series_books_sheet.dart@@ -1,6 +1,8 @@import 'dart:io';import 'package:flutter/material.dart';+import 'package:flutter/services.dart';import 'package:cached_network_image/cached_network_image.dart';+import 'overlay_toast.dart';import 'package:provider/provider.dart';import '../providers/auth_provider.dart';import '../providers/library_provider.dart';@@ -677,12 +679,8 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {await lib.addToAbsorbingQueue(bookId);lib.absorbingItemCache[bookId] = Map<String, dynamic>.from(book);if (context.mounted) {- ScaffoldMessenger.of(context).showSnackBar(SnackBar(- content: Text('Added "$bookTitle" to Absorbing'),- behavior: SnackBarBehavior.floating,- duration: const Duration(seconds: 2),- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),- ));+ HapticFeedback.mediumImpact();+ showOverlayToast(context, 'Added "$bookTitle" to Absorbing', icon: Icons.add_circle_outline_rounded);}return false; // keep item in list},