You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter Windows端用fluttertoast报错,求助win_toast插件使用方法

Flutter Windows桌面应用Toast解决方案

fluttertoast插件仅支持Android、iOS、Web等平台,不支持Windows,所以调用时会抛出MissingPluginException,找不到对应平台的方法实现。以下是使用win_toast: ^0.3.0实现Windows端Toast的完整步骤:

1. 安装依赖

在项目的pubspec.yaml中添加依赖:

dependencies:
  win_toast: ^0.3.0

执行flutter pub get完成依赖拉取。

2. 配置Windows项目

win_toast需要在Windows工程中完成注册配置:

  • 打开项目windows/runner/Main.cpp文件
  • 在文件顶部添加头文件引用:
    #include "win_toast/win_toast_plugin.h"
    
  • 在插件注册代码块中,添加插件注册语句:
    WinToastPlugin::RegisterWithRegistrar(registrar);
    

3. 替换原Toast函数

替换你现有的showToast函数为适配Windows的实现:

import 'package:win_toast/win_toast.dart';

void showToast(String message) {
  WinToast.showToast(
    title: "提示", // 可选,设置Toast标题
    subtitle: message, // 要展示的提示内容
    duration: WinToastDuration.short, // 显示时长,可选short/long
    // 可选:设置Toast图标,需将图标文件放入Windows项目资源目录
    // iconPath: "assets/toast_icon.ico",
  );
}

注意事项

Windows系统的通知规范不支持自定义Toast的背景色、文字颜色、字体大小这类Android/iOS端的个性化配置,win_toast的样式会遵循系统默认通知样式。如果需要更灵活的弹窗,也可以考虑使用自定义Dialog组件替代。

内容的提问来源于stack exchange,提问作者Muteeb Rehman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 08:28:20