From fded06c85aab76190440e43a286a99f1b5c2e2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=BCllner?= Date: Thu, 5 Mar 2026 18:37:47 +0100 Subject: [PATCH] fix(ux): show all global messages in front overlay for consistency --- lib/main.dart | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 5d50253..33e28ef 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -51,40 +51,25 @@ final supabase = Supabase.instance.client; /// Global keys so dialogs & snackbars survive widget-tree rebuilds. final navigatorKey = GlobalKey(); final scaffoldMessengerKey = GlobalKey(); -OverlayEntry? _activeErrorOverlay; -Timer? _activeErrorOverlayTimer; +OverlayEntry? _activeMessageOverlay; +Timer? _activeMessageOverlayTimer; /// Show a snackbar safely through the global key. void showGlobalSnackBar(String message, {bool isError = false}) { - if (isError) { - _showGlobalErrorOverlay(message); - return; - } - - final messenger = scaffoldMessengerKey.currentState; - if (messenger == null) return; - - messenger - ..hideCurrentSnackBar() - ..showSnackBar( - SnackBar( - content: Text(message), - backgroundColor: isError ? Colors.red : null, - behavior: SnackBarBehavior.floating, - margin: const EdgeInsets.fromLTRB(16, 0, 16, 96), - duration: const Duration(seconds: 3), - ), - ); + _showGlobalMessageOverlay(message, isError: isError); } -void _showGlobalErrorOverlay(String message) { +void _showGlobalMessageOverlay(String message, {required bool isError}) { final overlay = navigatorKey.currentState?.overlay; if (overlay == null) return; - _activeErrorOverlayTimer?.cancel(); - _activeErrorOverlay?.remove(); + _activeMessageOverlayTimer?.cancel(); + _activeMessageOverlay?.remove(); - _activeErrorOverlay = OverlayEntry( + final backgroundColor = isError ? Colors.red : const Color(0xFF1F2937); + final leadingIcon = isError ? Icons.error_outline : Icons.info_outline; + + _activeMessageOverlay = OverlayEntry( builder: (context) { final topPadding = MediaQuery.of(context).padding.top; return Positioned( @@ -98,7 +83,7 @@ void _showGlobalErrorOverlay(String message) { child: Container( padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12), decoration: BoxDecoration( - color: Colors.red, + color: backgroundColor, borderRadius: BorderRadius.circular(12), boxShadow: const [ BoxShadow( @@ -110,7 +95,7 @@ void _showGlobalErrorOverlay(String message) { ), child: Row( children: [ - const Icon(Icons.error_outline, color: Colors.white, size: 20), + Icon(leadingIcon, color: Colors.white, size: 20), const SizedBox(width: 8), Expanded( child: Text( @@ -129,12 +114,12 @@ void _showGlobalErrorOverlay(String message) { }, ); - overlay.insert(_activeErrorOverlay!); + overlay.insert(_activeMessageOverlay!); - _activeErrorOverlayTimer = Timer(const Duration(seconds: 4), () { - _activeErrorOverlay?.remove(); - _activeErrorOverlay = null; - _activeErrorOverlayTimer = null; + _activeMessageOverlayTimer = Timer(const Duration(seconds: 4), () { + _activeMessageOverlay?.remove(); + _activeMessageOverlay = null; + _activeMessageOverlayTimer = null; }); }