showTopSnackBar function
- OverlayState overlayState,
- Widget child, {
- Duration animationDuration = const Duration(milliseconds: 1200),
- Duration reverseAnimationDuration = const Duration(milliseconds: 550),
- Duration displayDuration = const Duration(milliseconds: 3000),
- VoidCallback? onTap,
- bool persistent = false,
- ControllerCallback? onAnimationControllerInit,
- EdgeInsets padding = const EdgeInsets.all(16),
- Curve curve = Curves.elasticOut,
- Curve reverseCurve = Curves.linearToEaseOut,
- SafeAreaValues safeAreaValues = const SafeAreaValues(),
- DismissType dismissType = DismissType.onTap,
- List<
DismissDirection> dismissDirection = const [DismissDirection.up],
The overlayState
argument is used to add specific overlay state.
If you are sure that there is a overlay state in your BuildContext,
You can get it Overlay.of(BuildContext)
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 animationDuration
argument is used to specify duration of
enter transition
The reverseAnimationDuration
argument is used to specify duration of
exit transition
The displayDuration
argument is used to specify duration displaying
The onTap
callback of _TopSnackBar
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.
The padding
argument is used to specify amount of outer padding
curve
and reverseCurve
arguments are used to specify curves
for in and out animations respectively
The safeAreaValues
argument is used to specify the arguments of the
SafeArea widget that wrap the snackbar.
The dismissType
argument specify which action to trigger to
dismiss the snackbar. Defaults to TopSnackBarDismissType.onTap
The dismissDirection
argument specify in which direction the snackbar
can be dismissed. This argument is only used when dismissType
is equal
to DismissType.onSwipe
. Defaults to [DismissDirection.up]
Implementation
void showTopSnackBar(
OverlayState overlayState,
Widget child, {
Duration animationDuration = const Duration(milliseconds: 1200),
Duration reverseAnimationDuration = const Duration(milliseconds: 550),
Duration displayDuration = const Duration(milliseconds: 3000),
VoidCallback? onTap,
bool persistent = false,
ControllerCallback? onAnimationControllerInit,
EdgeInsets padding = const EdgeInsets.all(16),
Curve curve = Curves.elasticOut,
Curve reverseCurve = Curves.linearToEaseOut,
SafeAreaValues safeAreaValues = const SafeAreaValues(),
DismissType dismissType = DismissType.onTap,
List<DismissDirection> dismissDirection = const [DismissDirection.up],
}) {
late OverlayEntry _overlayEntry;
_overlayEntry = OverlayEntry(
builder: (_) {
return _TopSnackBar(
onDismissed: () {
_overlayEntry.remove();
_previousEntry = null;
},
animationDuration: animationDuration,
reverseAnimationDuration: reverseAnimationDuration,
displayDuration: displayDuration,
onTap: onTap,
persistent: persistent,
onAnimationControllerInit: onAnimationControllerInit,
padding: padding,
curve: curve,
reverseCurve: reverseCurve,
safeAreaValues: safeAreaValues,
dismissType: dismissType,
dismissDirections: dismissDirection,
child: child,
);
},
);
if (_previousEntry != null && _previousEntry!.mounted) {
_previousEntry?.remove();
}
overlayState.insert(_overlayEntry);
_previousEntry = _overlayEntry;
}