toast static method

void toast({
  1. String? text,
  2. Widget? child,
  3. Widget? widget,
  4. AlignmentGeometry alignment = Alignment.bottomCenter,
  5. Curve curve = Curves.bounceOut,
  6. Function? onTap,
  7. Duration? duration,
  8. Duration openDuration = const Duration(milliseconds: 600),
  9. BorderRadiusGeometry? borderRadius,
  10. EdgeInsetsGeometry? padding,
  11. EdgeInsetsGeometry? margin,
  12. Color? backgroundColor,
  13. Color? textColor,
  14. List<BoxShadow>? boxShadow,
  15. TextStyle? textStyle,
  16. BoxBorder? border,
  17. double? width,
  18. TextAlign textAlign = TextAlign.center,
  19. TextOverflow overflow = TextOverflow.clip,
  20. int? maxLines,
})

Toast widget, no context required

Grock.toast(
 text: "Hello World",
 alignment: Alignment.topCenter,
 curve: Curves.bounceOut,
 duration: Duration(seconds: 4),
 openDuration: Duration(milliseconds: 600),
 borderRadius: BorderRadius.circular(10),
 padding: EdgeInsets.all(10),
 margin: EdgeInsets.all(10),
 backgroundColor: Colors.black54,
 textColor: Colors.white,
 boxShadow: [
  BoxShadow(color: Colors.black54, blurRadius: 10)
 ],
 textStyle: TextStyle(fontSize: 14),
 width: double.infinity,
 border: Border.all(color: Colors.white),
);

Implementation

static void toast({
  /// [text] or [child] or [widget] must be required
  String? text,

  /// [child] or [widget] must be required
  Widget? child,

  /// [child] or [text] must be required
  Widget? widget,

  /// toast position [Alignment.topCenter] or [Alignment.bottomCenter]
  AlignmentGeometry alignment = Alignment.bottomCenter,

  ///toast curve [Curves.bounceOut]
  Curve curve = Curves.bounceOut,

  /// toast tap event
  Function? onTap,

  /// toast duration [Duration(seconds: 4)]
  Duration? duration,

  /// toast open duration [Duration(milliseconds: 600)]
  Duration openDuration = const Duration(milliseconds: 600),

  /// toast border radius [BorderRadius.circular(10)]
  BorderRadiusGeometry? borderRadius,

  /// toast padding [EdgeInsets.all(10)]
  EdgeInsetsGeometry? padding,

  /// toast margin [EdgeInsets.all(10)]
  EdgeInsetsGeometry? margin,

  /// toast background color [Colors.black54]
  Color? backgroundColor,

  /// toast text color [Colors.white]
  Color? textColor,

  /// toast box shadow [BoxShadow(color: Colors.black54, blurRadius: 10)]
  List<BoxShadow>? boxShadow,

  /// toast text style [TextStyle(fontSize: 14)]
  TextStyle? textStyle,

  /// toast width [double.infinity]
  BoxBorder? border,

  /// toast width [double.infinity]
  double? width,

  /// toast text align [TextAlign.center]
  TextAlign textAlign = TextAlign.center,

  /// toast text overflow [TextOverflow.clip]
  TextOverflow overflow = TextOverflow.clip,

  /// toast text max lines [2]
  int? maxLines,
}) {
  OverlayState overlayState = Grock.navigationKey.currentState!.overlay!;
  late OverlayEntry overlayEntry;
  overlayEntry = OverlayEntry(
    builder: (context) {
      return _GrockToastWidget(
        overlayEntry: overlayEntry,
        text: text,
        onTap: onTap,
        widget: widget,
        openDuration: openDuration,
        borderRadius: borderRadius,
        padding: padding,
        margin: margin,
        backgroundColor: backgroundColor,
        textColor: textColor,
        boxShadow: boxShadow,
        textStyle: textStyle,
        alignment: alignment,
        width: width,
        curve: curve,
        duration: duration,
        border: border,
        child: child,
        textAlign: textAlign,
        overflow: overflow,
        maxLines: maxLines,
      );
    },
  );
  overlayState.insert(overlayEntry);
}