showTopSnackBar function
void
showTopSnackBar(
- BuildContext context,
- Widget child, {
- Duration showOutAnimationDuration = const Duration(milliseconds: 200),
- Duration hideOutAnimationDuration = const Duration(milliseconds: 550),
- Duration displayDuration = const Duration(milliseconds: 3000),
- double additionalTopPadding = 16.0,
- VoidCallback? onTap,
- OverlayState? overlayState,
Shows a SnackBar at the top of the screen.
Implementation
void showTopSnackBar(
BuildContext context,
Widget child, {
Duration showOutAnimationDuration = const Duration(milliseconds: 200),
Duration hideOutAnimationDuration = const Duration(milliseconds: 550),
Duration displayDuration = const Duration(milliseconds: 3000),
double additionalTopPadding = 16.0,
VoidCallback? onTap,
OverlayState? overlayState,
}) async {
overlayState ??= Overlay.of(context);
late OverlayEntry overlayEntry;
overlayEntry = OverlayEntry(
builder: (context) {
return _TopSnackBar(
showOutAnimationDuration: showOutAnimationDuration,
hideOutAnimationDuration: hideOutAnimationDuration,
displayDuration: displayDuration,
additionalTopPadding: additionalTopPadding,
onTap: () => onTap?.call(),
onDismissed: () {
overlayEntry.remove();
_previousEntry = null;
},
child: child,
);
},
);
_previousEntry?.remove();
overlayState.insert(overlayEntry);
_previousEntry = overlayEntry;
}