flutter

Tree-Shaking "MaterialIcons-Regular.otf" on flutter build


When i build my flutter project using flutter build apk this log show up:

Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 8776 bytes (99.5% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.

From my research tree-shaking is to eliminate dead code. I guess this "Materialicons-Regular.otf" is in my code but i never use it. And i search in my lib files, pubspec.yaml, there's not a single file mentioned that.

What i want to know, is "Materialicons-Regular.otf" come with flutter project initialization? If not, since i feel im not using it, how can i remove that? So maybe i can reduce my project size.

Thank you.

My flutter doctor:

[✓] Flutter (Channel stable, 3.22.2, on macOS 15.0 24A335 darwin-arm64, locale
    en-ID)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.93.1)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

Solution

  • MaterialIcons-Regular.otf contains the Material Icons used within Flutter projects through the Icons class. This file is included in your project if the uses-material-design: true flag is present in your pubspec.yaml file.

    To remove the MaterialIcons-Regular.otf from your project, simply remove mentioned flag. However, be cautious: many default Material widgets, like DropdownButton, rely on these icons. If you remove them without replacing the widgets or the icons they use, you’ll encounter issues such as missing icons being replaced with an "X" symbol.

    Here's an example of the relevant pubspec.yaml line:

    flutter:
      uses-material-design: true # Remove or comment out this line to exclude Material Icons
    

    That said, it’s generally recommended to keep the flag if you're using Material widgets. Flutter's tree-shaking process will automatically remove any unused icons, leaving only the ones your project actively requires. This ensures that the MaterialIcons-Regular.otf file remains optimized and doesn’t unnecessarily increase your app’s size.