show static method

void show(
  1. String msg, {
  2. int? duration = 1,
  3. int? gravity = 0,
  4. Color backgroundColor = const Color(0xAA000000),
  5. dynamic textStyle = const TextStyle(fontSize: 15, color: Colors.white),
  6. double backgroundRadius = 20,
  7. bool? rootNavigator,
  8. Border? border,
  9. bool webShowClose = false,
  10. Color webTexColor = const Color(0xFFffffff),
})

Implementation

static void show(String msg,
    {int? duration = 1,
    int? gravity = 0,
    Color backgroundColor = const Color(0xAA000000),
    textStyle = const TextStyle(fontSize: 15, color: Colors.white),
    double backgroundRadius = 20,
    bool? rootNavigator,
    Border? border,
    bool webShowClose = false,
    Color webTexColor = const Color(0xFFffffff)}) {
  if (ToastContext().context == null) {
    throw Exception('Context is null, please call ToastContext.init(context) first');
  }
  if (kIsWeb == true) {
    if (ToastContext()._channel == null) {
      ToastContext()._channel = const MethodChannel('appdev/FlutterToast');
    }
    String toastGravity = "bottom";
    if (gravity == Toast.top) {
      toastGravity = "top";
    } else if (gravity == Toast.center) {
      toastGravity = "center";
    } else {
      toastGravity = "bottom";
    }

    final Map<String, dynamic> params = <String, dynamic>{
      'msg': msg,
      'duration': (duration ?? 1) * 1000,
      'gravity': toastGravity,
      'bgcolor': backgroundColor.toString(),
      'textcolor': webTexColor.value.toRadixString(16),
      'webShowClose': webShowClose,
    };
    ToastContext()._channel?.invokeMethod("showToast", params);
  } else {
    ToastView.dismiss();
    ToastView.createView(msg, ToastContext().context!, duration, gravity, backgroundColor,
        textStyle, backgroundRadius, border, rootNavigator);
  }
}