showTopSnackBar function
- BuildContext context,
- Widget child, {
- Duration showOutAnimationDuration = const Duration(milliseconds: 1200),
- Duration hideOutAnimationDuration = const Duration(milliseconds: 550),
- Duration displayDuration = const Duration(milliseconds: 3000),
- double additionalTopPadding = 16.0,
- VoidCallback? onTap,
- OverlayState? overlayState,
- double leftPadding = 16,
- double rightPadding = 16,
- bool persistent = false,
- ControllerCallback? onAnimationControllerInit,
Displays a widget that will be passed to child
parameter above the current
contents of the app, with transition animation
The child
argument is used to pass widget that you want to show
The showOutAnimationDuration
argument is used to specify duration of
enter transition
The hideOutAnimationDuration
argument is used to specify duration of
exit transition
The displayDuration
argument is used to specify duration displaying
The additionalTopPadding
argument is used to specify amount of top
padding that will be added for SafeArea values
The onTap
callback of TopSnackBar
The overlayState
argument is used to add specific overlay state.
If you will not pass it, it will try to get the current overlay state from
passed BuildContext
The persistent
argument is used to make snack bar persistent, so
displayDuration
will be ignored. Default is false.
The onAnimationControllerInit
callback is called on internal
AnimationController has been initialized.
Implementation
void showTopSnackBar(
BuildContext context,
Widget child, {
Duration showOutAnimationDuration = const Duration(milliseconds: 1200),
Duration hideOutAnimationDuration = const Duration(milliseconds: 550),
Duration displayDuration = const Duration(milliseconds: 3000),
double additionalTopPadding = 16.0,
VoidCallback? onTap,
OverlayState? overlayState,
double leftPadding = 16,
double rightPadding = 16,
bool persistent = false,
ControllerCallback? onAnimationControllerInit,
}) async {
overlayState ??= Overlay.of(context);
late OverlayEntry overlayEntry;
overlayEntry = OverlayEntry(
builder: (context) {
return TopSnackBar(
child: child,
onDismissed: () {
if (overlayEntry.mounted && _previousEntry == overlayEntry) {
overlayEntry.remove();
_previousEntry = null;
}
},
showOutAnimationDuration: showOutAnimationDuration,
hideOutAnimationDuration: hideOutAnimationDuration,
displayDuration: displayDuration,
additionalTopPadding: additionalTopPadding,
onTap: onTap,
leftPadding: leftPadding,
rightPadding: rightPadding,
persistent: persistent,
onAnimationControllerInit: onAnimationControllerInit,
);
},
);
if (_previousEntry != null && _previousEntry!.mounted) {
_previousEntry?.remove();
}
overlayState?.insert(overlayEntry);
_previousEntry = overlayEntry;
}