颤动图标

设计与多媒体 社区

技能解读

当前原文的自动摘译,尚未人工审校。

论点

$ARGUMENTS — 所需图标设计的可选描述。如果为空,请重新设计现有图标或为项目使用合理的默认值。

为什么存在这些规则

Android API 26+ 使用自适应图标:操作系统在背景层(纯色或图像)上合成前景层(具有透明背景的 PNG),然后使用形状遮罩(方圆、圆形等)对两者进行剪辑。如果您将圆角烘焙到源图像中,Android 会再次剪辑它→“图标内的图标”。 iOS 将自己的方格蒙版应用于全出血方形。预烘焙的圆角在圆角内留下可见的角填充→相同的插图问题。

正确做法

资源 · 背景 · 圆角 · 注释 app_icon_ios.png · 全出血纯色 · ❌ 无 · iOS 添加自己的遮罩 app_icon_foreground.png · 透明 (RGBA) · ❌ 无 · Android 前景层;内容必须适合安全区域 Android 安全区域:无论遮罩形状如何,画布的中心 72/108 = 66.7% 始终可见。将所有有意义的内容(outer_r 等)保留在该区域内。对于 1024 像素画布:安全 = 683 像素,因此 outer_r ≤ 340。

1. 检查先决条件

在 dev_dependencies 中检查 pubspec.yaml 中的 flutter_launcher_icons。如果不存在,请添加:

3. 使用Python/Pillow生成图标PNG

编写并运行一个 Python 脚本,生成两个文件: assets/icon/app_icon_ios.png — 1024×1024,全出血方形 使用 Image.new('RGBA', (size, size), bg_color) 作为背景 — 而不是 draw.rounded_rectangle。边缘到边缘的设计; iOS 会自动剪辑成方圆形状。 assets/icon/app_icon_foreground.png — 1024×1024,透明背景

流狐档案 运行与权限由流狐静态检查推断,不代表作者声明或实际测试结果。
领域
设计与多媒体
作者声明的智能体
未找到明确声明;不据此推断已兼容或已测试
静态检查
88 / 100 · 启发式扫描,不代表运行安全
运行环境证据
未执行;当前没有隔离运行测试证据
作者 / 版本 / 许可证
@tomevault-io · 未声明许可证
上下文用量评级
低消耗
接入复杂程度
即装即用
是否需要外部接口密钥
不需要
兼容的系统
未声明(默认跨平台)
运行环境要求
Python
检测到的文件与系统行为
  • 只读
  • 允许写入 / 修改
网络行为
仅限本地
安装命令数
无(仅作为资料)

需要注意: 未声明工具权限范围;实际权限由运行环境决定。

作者说明文件(原文) SKILL.md

# Flutter App Icon Generator

Generate or update the app icon for a Flutter project correctly across Android (adaptive) and iOS (full-bleed).

## Arguments
`$ARGUMENTS` — Optional description of the desired icon design. If empty, redesign the existing icon or use a sensible default for the project.

## Rules — read before touching any file

### Why these rules exist
- **Android API 26+** uses adaptive icons: the OS composites a *foreground layer* (PNG with transparent bg) over a *background layer* (solid color or image) and then clips both with a shape mask (squircle, circle, etc.). If you bake rounded corners into the source image, Android clips it again → "icon inside icon."
- **iOS** applies its own squircle mask to a full-bleed square. Pre-baked rounded corners leave visible corner padding inside the squircle → same inset problem.

### Correct approach
| Asset | Background | Rounded corners | Notes |
|---|---|---|---|
| `app_icon_ios.png` | Full-bleed solid color | ❌ None | iOS adds its own mask |
| `app_icon_foreground.png` | Transparent (RGBA) | ❌ None | Android foreground layer; content must fit inside safe zone |

**Android safe zone:** the center 72/108 = **66.7%** of the canvas is always visible regardless of mask shape. Keep all meaningful content (outer_r, etc.) within that region. For a 1024 px canvas: safe = 683 px, so `outer_r ≤ 340`.

## Steps

### 1. Check prerequisites

```bash
python3 -c "from PIL import Image; print('ok')" 2>/dev/null || pip3 install Pillow
```

Check `pubspec.yaml` for `flutter_launcher_icons` in dev_dependencies. If absent, add it:
```yaml
dev_dependencies:
  flutter_launcher_icons: ^0.14.1
```

### 2. Create icon assets directory

```bash
mkdir -p assets/icon
```

### 3. Generate icon PNGs with Python/Pillow

Write and run a Python script that produces **two files**:

#### `assets/icon/app_icon_ios.png` — 1024×1024, full-bleed square
```python
from PIL import Image, ImageDraw
size = 1024
img = Image.new('RGBA', (size, size), BACKGROUND_COLOR)  # solid fill, no rounded_rectangle
draw = ImageDraw.Draw(img)
# ... draw design centered on canvas ...
img.save('assets/icon/app_icon_ios.png')
```
- Use `Image.new('RGBA', (size, size), bg_color)` for the background — **not** `draw.rounded_rectangle`.
- Design fills edge-to-edge; iOS clips to squircle automatically.

#### `assets/icon/app_icon_foreground.png` — 1024×1024, transparent background
```python
fg = Image.new('RGBA', (size, size), (0, 0, 0, 0))  # fully transparent
draw = ImageDraw.Draw(fg)
# ... draw design centered, scaled so outer_r ≤ 340 for 1024px canvas ...
# When cutting out a center hole in a donut, fill with (0,0,0,0) not the bg color
fg.save('assets/icon/app_icon_foreground.png')
```
- Background **must be transparent** — `(0, 0, 0, 0)`.
- Any "hole" in the design (donut center, gaps) must also be `(0, 0, 0, 0)`.
- Scale all radii/sizes proportionally so content stays inside the 683 px safe zone.

### 4. Update `pubspec.yaml`

Set the `flutter_launcher_icons` section to:
```yaml
flutter_launcher_icons:
  android: true
  ios: true
  image_path_android: "assets/icon/app_icon_ios.png"   # legacy Android (API < 26)
  image_path_ios: "assets/icon/app_icon_ios.png"
  adaptive_icon_background: "#RRGGBB"                  # match the bg color used in app_icon_ios.png
  adaptive_icon_foreground: "assets/icon/app_icon_foreground.png"
  min_sdk_android: 21
  remove_alpha_ios: true
```

- `image_path_android` (legacy) and `image_path_ios` must both be present — the tool errors if either is missing when using the split-path form.
- `adaptive_icon_background` is a hex color string matching the background of `app_icon_ios.png`.
- Do **not** use the single `image_path` key when you also set adaptive icon keys.

### 5. Run the generator

```bash
flutter pub get && dart run flutter_launcher_icons
```

Expected output includes:
- `• Creating adaptive icons Android`
- `• Creating mipmap xml file Android`
- `✓ Successfully generated launcher icons`

Verify that `android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml` was created — this is the adaptive icon XML. If it's missing, the Android "icon inside icon" bug is not fixed.

### 6. Verify

After running, confirm:
- `android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml` exists and references `@color/ic_launcher_background` + `@drawable/ic_launcher_foreground`
- `android/app/src/main/res/values/colors.xml` contains the `ic_launcher_background` color
- `ios/Runner/Assets.xcassets/AppIcon.appiconset/` contains updated PNGs

## Common mistakes to avoid

- ❌ Drawing the background with `draw.rounded_rectangle(...)` — causes double-rounding on both platforms
- ❌ Filling the donut center hole with the background color in the foreground PNG — should be `(0,0,0,0)`
- ❌ Omitting `image_path_android` when using `image_path_ios` — tool will error
- ❌ Making `outer_r > 340` on a 1024px foreground — content gets clipped by aggressive masks (circle)
- ❌ Using a single `image_path` for both platforms — loses adaptive icon support on Android

---
> Source: [albertopeam/macro-tracker](https://github.com/albertopeam/macro-tracker) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->

讨论

基于 GitHub Discussions。登录 GitHub 即可参与讨论、点赞、订阅更新。