createView method

Future createView({
  1. required String message,
  2. required BuildContext context,
  3. BoxDecoration? decoration,
  4. AlignToast alignToast = AlignToast.top,
  5. double fontSize = size14,
  6. Widget? icon,
  7. FontWeight fontWeight = fontWeigh500,
  8. Color fontColor = whiteColor,
  9. int durationMilliSeconds = 2500,
})

Implementation

Future createView(
    {required String message,
    required BuildContext context,
    BoxDecoration? decoration,
    AlignToast alignToast = AlignToast.top,
    double fontSize = size14,
    Widget? icon,
    FontWeight fontWeight = fontWeigh500,
    Color fontColor = whiteColor,
    int durationMilliSeconds = 2500}) async {
  if (isVisible) {
    return;
  }
  isVisible = true;
  overlayState = Overlay.of(context)!;
  overlayEntry = OverlayEntry(
      builder: (BuildContext context) => Positioned(
            child: SafeArea(
                child: ToastAnimateState(
              alignToast: alignToast,
              fontWeight: fontWeight,
              icon: icon,
              endTween: alignToast == AlignToast.top ? 10.0 : -10.0,
              startTween: alignToast == AlignToast.top ? -5.0 : 5.0,
              fontSize: fontSize,
              fontColor: fontColor,
              decoration: decoration,
              message: message,
              durationSeconds: durationMilliSeconds,
              removeWidget: () {
                if (overlayState != null) {
                  if (overlayEntry != null && overlayEntry!.mounted) {
                    overlayEntry!.remove();
                    isVisible = false;
                  }
                }
              },
            )),
            top: alignToast == AlignToast.top
                ? MediaQuery.of(context).viewInsets.top + 5
                : null,
            bottom: alignToast == AlignToast.bottom
                ? MediaQuery.of(context).viewInsets.bottom + 20
                : null,
            key: UniqueKey(),
          ));
  overlayState!.insert(overlayEntry!);
}