showAlertBanner function

dynamic showAlertBanner(
  1. BuildContext context,
  2. VoidCallback onTap,
  3. Widget child, {
  4. AlertBannerLocation alertBannerLocation = AlertBannerLocation.top,
  5. double? maxLength,
  6. Duration? durationOfStayingOnScreen,
  7. Duration? durationOfScalingUp,
  8. Duration? durationOfScalingDown,
  9. Duration? durationOfLeavingScreenBySwipe,
  10. Curve? curveScaleUpAnim,
  11. Curve? curveScaleDownAnim,
  12. Curve? curveTranslateAnim,
  13. bool safeAreaTopEnabled = true,
  14. bool safeAreaBottomEnabled = true,
  15. bool safeAreaLeftEnabled = true,
  16. bool safeAreaRightEnabled = true,
})

Implementation

dynamic showAlertBanner(
  BuildContext context,
  VoidCallback onTap,
  Widget child, {
  AlertBannerLocation alertBannerLocation = AlertBannerLocation.top,
  double? maxLength,
  Duration? durationOfStayingOnScreen,
  Duration? durationOfScalingUp,
  Duration? durationOfScalingDown,
  Duration? durationOfLeavingScreenBySwipe,
  Curve? curveScaleUpAnim,
  Curve? curveScaleDownAnim,
  Curve? curveTranslateAnim,
  bool safeAreaTopEnabled = true,
  bool safeAreaBottomEnabled = true,
  bool safeAreaLeftEnabled = true,
  bool safeAreaRightEnabled = true,
}) {
  OverlayEntry? overlay;
  overlay = OverlayEntry(
    builder: (context) {
      return Align(
        alignment: alertBannerLocation == AlertBannerLocation.top
            ? Alignment.topCenter
            : Alignment.bottomCenter,
        child: SafeArea(
          top: safeAreaTopEnabled,
          bottom: safeAreaBottomEnabled,
          left: safeAreaLeftEnabled,
          right: safeAreaRightEnabled,
          child: _OverlayItem(
            onTap: onTap,
            curveScaleDownAnim: curveScaleDownAnim ?? Curves.decelerate,
            curveScaleUpAnim: curveScaleUpAnim ?? Curves.easeOutBack,
            curveTranslateAnim: curveTranslateAnim ?? Curves.ease,
            durationOfScalingUp:
                durationOfScalingUp ?? const Duration(milliseconds: 400),
            durationOfScalingDown:
                durationOfScalingDown ?? const Duration(milliseconds: 250),
            durationOfLeavingScreenBySwipe: durationOfLeavingScreenBySwipe ??
                const Duration(milliseconds: 1500),
            alertBannerLocation: alertBannerLocation,
            maxWidth: maxLength,
            overlay: overlay,
            duration:
                durationOfStayingOnScreen ?? const Duration(milliseconds: 3500),
            child: child,
          ),
        ),
      );
    },
  );
  Overlay.of(context)?.insert(overlay);
}