flutter_launcher_icons如何使用

想在Flutter项目中使用flutter_launcher_icons插件来更换应用图标,但不太清楚具体操作步骤。我已经按照文档在pubspec.yaml中添加了依赖,但运行flutter pub get后不知道接下来该做什么。请问如何配置图标路径?是否需要特定尺寸的图片?生成的图标会自动覆盖所有平台吗?iOS和Android的配置方式是否有区别?求详细的使用教程。

2 回复

使用 flutter_launcher_icons 很简单,只需几步:

  1. 安装依赖
    pubspec.yamldev_dependencies 下添加:

    dev_dependencies:
      flutter_launcher_icons: ^0.13.1
    
  2. 配置图标
    pubspec.yaml 中新增配置段(与 dependencies 同级):

    flutter_launcher_icons:
      image_path: "assets/icon/icon.png"  # 图标路径
      android: true
      ios: true
    
  3. 生成图标
    终端执行:

    flutter pub get
    flutter pub run flutter_launcher_icons:main
    
  4. 检查结果

    • Android 图标在 android/app/src/main/res
    • iOS 图标在 ios/Runner/Assets.xcassets/AppIcon.appiconset

注意:

  • 推荐图标尺寸 1024x1024,工具会自动缩放
  • iOS 需用 flutter clean 清理缓存后重新编译

更多关于flutter_launcher_icons如何使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


Flutter Launcher Icons 是一个用于自动生成应用图标的 Flutter 插件。以下是使用步骤:

  1. 添加依赖
    pubspec.yamldev_dependencies 中添加:

    dev_dependencies:
      flutter_launcher_icons: ^0.13.1
    
  2. 配置图标路径
    pubspec.yaml 中新增配置段:

    flutter_launcher_icons:
      android: true
      ios: true
      image_path: "assets/icon/icon.png"  # 主图标路径
      # 可选:为不同平台指定不同图标
      # android: "assets/icon/android_icon.png"
      # ios: "assets/icon/ios_icon.png"
    
  3. 生成图标
    运行命令:

    flutter pub get
    flutter pub run flutter_launcher_icons:main
    
  4. 验证结果

    • Android:检查 android/app/src/main/res/mipmap-* 下的图标
    • iOS:检查 ios/Runner/Assets.xcassets/AppIcon.appiconset 内容

注意事项

  • 推荐图标尺寸:1024x1024 像素(确保包含各平台所需的所有分辨率)
  • iOS 需额外在 ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json 中确认图标配置
  • 可配置自适应图标(Android 8+):
    flutter_launcher_icons:
      android: "adaptive_icon"
      image_path: "assets/icon/foreground.png"
      adaptive_icon_foreground: "assets/icon/foreground.png"
      adaptive_icon_background: "assets/icon/background.png"
    

完成操作后重新编译应用即可生效。

回到顶部