字节笔记本

2026年2月22日

flutter_acrylic:Flutter 桌面窗口视觉效果库

flutter_acrylic 是一个 Flutter 插件,用于在 Windows、macOS 和 Linux 桌面平台上实现窗口的亚克力(Acrylic)、云母(Mica)和透明效果。该项目在 GitHub 上获得了 651 stars,是 Flutter 桌面开发中实现现代化 UI 效果的热门选择。

项目简介

flutter_acrylic 由 Hitesh Kumar Saini 开发维护,支持以下平台:

平台状态维护者
Windows✅ 支持Hitesh Kumar Saini
macOS✅ 支持Adrian Samoticha
Linux✅ 支持Hitesh Kumar Saini

该库利用 Windows 上的 DwmSetWindowAttribute API(Windows 11)和未文档化的 SetWindowCompositionAttribute API(旧版本 Windows),以及 Linux 上的 cairo 图形库来实现各种视觉效果。

核心特性

  • 窗口亚克力效果:创建半透明纹理效果,增加视觉层次感
  • 云母效果:动态材质,融合主题和桌面壁纸背景
  • Tabbed 效果:类似云母但对桌面壁纸颜色更敏感
  • 透明背景:完全透明的窗口背景
  • Aero 玻璃效果:Windows Vista/7 风格的光泽模糊效果
  • 跨平台支持:一套代码同时支持 Windows、macOS 和 Linux
  • macOS 专属效果:标题栏、菜单、侧边栏、HUD 窗口等多种材质效果

安装指南

pubspec.yaml 中添加依赖:

yaml
dependencies:
  flutter_acrylic: ^1.1.0

快速开始

初始化插件

dart
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Window.initialize();
  runApp(MyApp());
}

应用亚克力效果

dart
await Window.setEffect(
  effect: WindowEffect.acrylic,
  color: Color(0xCC222222),
);

应用云母效果

dart
await Window.setEffect(
  effect: WindowEffect.mica,
  dark: true,
);

可用效果一览

Windows 支持的效果

效果描述最低版本要求
transparent透明窗口背景所有版本
disabled默认窗口背景所有版本
solid纯色背景所有版本
aeroAero 玻璃效果Windows Vista+
acrylic亚克力效果Windows 10 1803+
mica云母效果Windows 11
tabbedTabbed 效果Windows 11 build 22523+

macOS 支持的效果

效果描述
titlebar窗口标题栏材质
menu菜单背景材质
popover弹出窗口背景
sidebar侧边栏背景
headerView页眉/页脚视图
sheet工作表窗口背景
hudWindowHUD 窗口背景
fullScreenUI全屏模态界面
toolTip工具提示背景
contentBackground不透明内容背景
underWindowBackground窗口背景下层
underPageBackground文档页面背后

其他实用功能

全屏控制

dart
// 进入全屏
Window.enterFullscreen();

// 退出全屏
Window.exitFullscreen();

窗口控制按钮

dart
// 隐藏窗口控制按钮
Window.hideWindowControls();

// 显示窗口控制按钮
Window.showWindowControls();

macOS 专属功能

dart
// 获取标题栏高度
final titlebarHeight = Window.getTitlebarHeight();

// 设置文档编辑状态
Window.setDocumentEdited();
Window.setDocumentUnedited();

// 设置窗口代表文件
Window.setRepresentedFilename('path/to/file.txt');
Window.setRepresentedUrl('https://flutter.dev');

// 标题栏控制
Window.hideTitle();
Window.showTitle();
Window.makeTitlebarTransparent();

技术实现

  • Windows: 使用 DwmSetWindowAttribute API(Windows 11)和 SetWindowCompositionAttribute API(旧版本)
  • Linux: 使用 cairo 图形库
  • macOS: 使用原生 AppKit 材质 API

项目链接

分享: