showToast static method

Future<bool?> showToast({
  1. required String msg,
  2. Toast? toastLength,
  3. int timeInSecForIosWeb = 1,
  4. double? fontSize,
  5. ToastGravity? gravity,
  6. Color? backgroundColor,
  7. Color? textColor,
  8. bool webShowClose = false,
  9. dynamic webBgColor = "linear-gradient(to right, #00b09b, #96c93d)",
  10. dynamic webPosition = "right",
})

Summons the platform's showToast which will display the message

Wraps the platform's native Toast for android. Wraps the Plugin https://github.com/scalessec/Toast for iOS Wraps the https://github.com/apvarun/toastify-js for Web

Parameter msg is required and all remaining are optional

Implementation

static Future<bool?> showToast({
  required String msg,
  Toast? toastLength,
  int timeInSecForIosWeb = 1,
  double? fontSize,
  ToastGravity? gravity,
  Color? backgroundColor,
  Color? textColor,
  bool webShowClose = false,
  webBgColor = "linear-gradient(to right, #00b09b, #96c93d)",
  webPosition = "right",
}) async {
  String toast = "short";
  if (toastLength == Toast.LENGTH_LONG) {
    toast = "long";
  }

  String gravityToast = "bottom";
  if (gravity == ToastGravity.TOP) {
    gravityToast = "top";
  } else if (gravity == ToastGravity.CENTER) {
    gravityToast = "center";
  } else {
    gravityToast = "bottom";
  }

//lines from 78 to 97 have been changed in order to solve issue #328
  if (backgroundColor == null) {
    backgroundColor = Colors.black;
  }
  if (textColor == null) {
    textColor = Colors.white;
  }
  final Map<String, dynamic> params = <String, dynamic>{
    'msg': msg,
    'length': toast,
    'time': timeInSecForIosWeb,
    'gravity': gravityToast,
    'bgcolor': backgroundColor.value,
    'iosBgcolor': backgroundColor.value,
    'textcolor': textColor.value,
    'iosTextcolor': textColor.value,
    'fontSize': fontSize,
    'webShowClose': webShowClose,
    'webBgColor': webBgColor,
    'webPosition': webPosition
  };

  bool? res = await _channel.invokeMethod('showToast', params);
  return res;
}