createView static method

void createView(
  1. String msg,
  2. BuildContext context,
  3. int? duration,
  4. int gravity,
  5. Color background,
  6. TextStyle? textStyle,
  7. double backgroundRadius,
  8. Border? border,
  9. bool? rootNavigator,
)

Implementation

static void createView(
    String msg,
    BuildContext context,
    int? duration,
    int gravity,
    Color background,
    TextStyle? textStyle,
    double backgroundRadius,
    Border? border,
    bool? rootNavigator) async {
  overlayState = Overlay.of(context, rootOverlay: rootNavigator ?? false);

  _overlayEntry = new OverlayEntry(
    builder: (BuildContext context) => ToastWidget(
        duration: Duration(
            seconds: duration == null ? Alert.lengthShort : duration),
        widget: Container(
          width: MediaQuery.of(context).size.width,
          child: Container(
              alignment: Alignment.center,
              width: MediaQuery.of(context).size.width,
              child: Container(
                decoration: BoxDecoration(
                  color: background,
                  borderRadius: BorderRadius.circular(backgroundRadius),
                  border: border,
                ),
                margin: EdgeInsets.symmetric(horizontal: 20),
                padding: EdgeInsets.fromLTRB(16, 10, 16, 10),
                child: Text(msg, softWrap: true, style: textStyle),
              )),
        ),
        gravity: gravity),
  );
  _isVisible = true;
  overlayState!.insert(_overlayEntry!);
  await new Future.delayed(
      Duration(seconds: duration == null ? Alert.lengthShort : duration));
  dismiss();
}