import 'package:flutter/material.dart'; /// Shows a snackbar-style message at the top of the screen (for success/neutral feedback). void showTopSnackBar( BuildContext context, { required String message, Color? backgroundColor, Duration duration = const Duration(seconds: 2), }) { final overlay = Overlay.of(context); final theme = Theme.of(context); final color = backgroundColor ?? theme.colorScheme.surfaceContainerHighest; final textColor = backgroundColor != null ? Colors.white : theme.colorScheme.onSurface; late OverlayEntry entry; entry = OverlayEntry( builder: (context) => Positioned( top: 0, left: 0, right: 0, child: SafeArea( child: Padding( padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), child: Material( color: color, elevation: 4, borderRadius: BorderRadius.circular(8), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14), child: Text( message, style: theme.textTheme.bodyLarge?.copyWith(color: textColor), ), ), ), ), ), ), ); overlay.insert(entry); Future.delayed(duration, () { entry.remove(); }); }