📁 Deep Dive · Beginner

Chỉ ship asset mà từng nền tảng cần

Một danh sách flutter: assets từng khiến mọi nền tảng nhận mọi file. Từ 3.41 bạn lọc được:

Sơ đồ: Platform-specific Assets

flutter:
  assets:
    - path: assets/logo.png
    - path: assets/web_worker.js
      platforms: [web]
    - path: assets/desktop_icon.png
      platforms: [windows, linux, macos]

Vì sao app đa nền tảng nên làm

  • User mobile không nên tải PDF hướng dẫn desktop hay web worker.
  • Metric dung lượng store và ma sát download cải thiện ngay.
  • CI assert được ma trận asset theo nền tảng.

Cách chia thực tế

Loại assetNền tảng
Branding dùng chungall
Web worker / helper wasmweb
Template in ấn độ phân giải caodesktop
Nhạc notification iOS/Androidandroid, ios

Cạm bẫy

  • rootBundle.load asset không tồn tại trên nền tảng sẽ throw — guard bằng platform check.
  • Đây là lọc đóng gói, không phải theming runtime.
#Flutter#Assets#AppSize#pubspec