showSnackbar method

void showSnackbar({
  1. String? title,
  2. String? subTitle,
  3. TextStyle? titleStyle,
  4. TextStyle? subTitleStyle,
  5. Widget? titleWidget,
  6. Widget? subTitleWidget,
  7. Widget? leading,
  8. Widget? trailing,
  9. Color? backgroundColor,
  10. Duration? duration,
  11. EdgeInsetsGeometry? contentPadding,
  12. EdgeInsetsGeometry? outerPadding,
  13. BorderRadius? borderRadius,
  14. Curve? animationCurve,
  15. AnimateFrom? animateFrom,
})

Implementation

void showSnackbar({
  String? title,
  String? subTitle,
  TextStyle? titleStyle,
  TextStyle? subTitleStyle,
  Widget? titleWidget,
  Widget? subTitleWidget,
  Widget? leading,
  Widget? trailing,
  Color? backgroundColor,
  Duration? duration,
  EdgeInsetsGeometry? contentPadding,
  EdgeInsetsGeometry? outerPadding,
  BorderRadius? borderRadius,
  Curve? animationCurve,
  AnimateFrom? animateFrom,
}) {
  // Get the OverlayState
  final overlayState = Overlay.of(this);
  // Create an OverlayEntry with your custom widget
  final snackBar = OverlayEntry(
    builder: (_) => SnackbarWidget(
      title: title ??= "",
      subTitle: subTitle ??= "",
      titleStyle: titleStyle ??= const TextStyle(color: Colors.white),
      subTitleStyle: subTitleStyle ??= const TextStyle(color: Colors.white),
      titleWidget: titleWidget,
      subTitleWidget: subTitleWidget,
      leading: leading,
      trailing: trailing,
      backgroundColor: backgroundColor ??= Colors.blue,
      duration: duration ??= const Duration(milliseconds: 1000),
      contentPadding: contentPadding ??= const EdgeInsets.all(20),
      borderRadius: borderRadius ??= BorderRadius.circular(10),
      animationCurve: animationCurve ??= Curves.ease,
      outerPadding: outerPadding ??=
          const EdgeInsets.symmetric(horizontal: 10),
      animateFrom: animateFrom ?? AnimateFrom.fromBottom,
    ),
  );
  // then insert it to the overlay
  // this will show the toast widget on the screen
  overlayState!.insert(snackBar);
  // 3 secs later remove the toast from the stack
  // and this one will remove the toast from the screen
  Future.delayed(duration! * 2, snackBar.remove);
}