cancel method

  1. @override
Future<bool?> cancel()
override

取消当前显示的 Toast

通过方法通道调用原生平台的 cancel 方法, 立即隐藏当前正在显示的 Toast

返回 Future<bool?> 表示操作是否成功

Implementation

@override
Future<bool?> cancel() async {
  try {
    // 调用原生平台的 'cancel' 方法
    // 各平台原生代码需要实现此方法来隐藏 Toast
    final bool? result = await channel.invokeMethod("cancel");
    return result;
  } on PlatformException catch (e) {
    // 捕获平台异常,在调试模式下打印错误信息
    if (kDebugMode) {
      print('MethodChannelDencendToast.cancel failed: ${e.message}');
    }
    return false;
  }
}