toast static method
void
toast({
- String? text,
- Widget? child,
- Widget? widget,
- AlignmentGeometry alignment = Alignment.bottomCenter,
- Curve curve = Curves.bounceOut,
- Function? onTap,
- Duration? duration,
- Duration openDuration = const Duration(milliseconds: 600),
- BorderRadiusGeometry? borderRadius,
- EdgeInsetsGeometry? padding,
- EdgeInsetsGeometry? margin,
- Color? backgroundColor,
- Color? textColor,
- List<
BoxShadow> ? boxShadow, - TextStyle? textStyle,
- BoxBorder? border,
- double? width,
- TextAlign textAlign = TextAlign.center,
- TextOverflow overflow = TextOverflow.clip,
- 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);
}