showToast static method
Show the msg via native platform's toast.
On Android uses Toast. On iOS uses https://github.com/scalessec/Toast plugin. On web uses https://github.com/apvarun/toastify-js library.
Parameter msg is required and all remaining are optional.
The fontAsset is the path to your Flutter asset to use in toast.
If not specified platform's default font will be used.
Implementation
static Future<bool?> showToast({
required String msg,
Toast? toastLength,
int timeInSecForIosWeb = 1,
double? fontSize,
String? fontAsset,
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";
}
if (backgroundColor == null && !kIsWeb && Platform.isIOS) {
backgroundColor = Colors.black;
}
if (textColor == null && !kIsWeb && Platform.isIOS) {
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,
'fontAsset': fontAsset,
'webShowClose': webShowClose,
'webBgColor': webBgColor,
'webPosition': webPosition
};
bool? res = await _channel.invokeMethod('showToast', params);
return res;
}