Content-Length: 351668 | pFad | https://github.com/flutter/flutter/issues/126261

61 Icon tree shaking ignores IconData implementation getters · Issue #126261 · flutter/flutter · GitHub
Skip to content

Icon tree shaking ignores IconData implementation getters #126261

@Albert221

Description

@Albert221
import 'package:flutter/material.dart';

enum MyIcons implements IconData {
  test(58332);

  const MyIcons(this.codePoint);

  @override
  final int codePoint;

  @override
  String get fontFamily => 'MaterialIcons';

  @override
  final String? fontPackage = null;

  @override
  final bool matchTextDirection = false;
}

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          leading: const Icon(MyIcons.test),
        ),
      ),
    ),
  );
}

Given the code above in a fresh flutter create project, run the flutter build apk. You'll see fail:

➜  icon_shaking flutter build apk

💪 Building with sound null safety 💪

Target aot_android_asset_bundle failed: IconTreeShakerException: Invalid ConstFinder result. Expected "fontPackage" to be a String, "fontFamily" to be a String, and "codePoint" to be an int, got: {codePoint: 58332, fontPackage: null, matchTextDirection: false, index: 0, _name: test}.

To disable icon tree shaking, pass --no-tree-shake-icons to the requested flutter build command


FAILURE: Build failed with an exception.

* Where:
Script '/Users/albert/fvm/versions/3.7.12/packages/flutter_tools/gradle/flutter.gradle' line: 1157

* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command '/Users/albert/fvm/versions/3.7.12/bin/flutter'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 12s
Running Gradle task 'assembleRelease'...                           13.1s
Gradle task assembleRelease failed with exit code 1

This is because of the fontFamily getter. If I'd replace the getter with a normal field (final fontFamily = 'MaterialIcons';) then it works correctly.

The same problem happens with codePoint and fontPackage.

Of course, the MaterialIcons font is used here just as an example. In our project we use a custom icon font and provide the IconData with such enum.

Here's the source of the thrown exception:

throw IconTreeShakerException._(
'Invalid ConstFinder result. Expected "fontPackage" to be a String, '
'"fontFamily" to be a String, and "codePoint" to be an int, '
'got: $iconDataMap.');

flutter --version
Flutter 3.7.12 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 4d9e56e694 (3 weeks ago) • 2023-04-17 21:47:46 -0400
Engine • revision 1a65d409c7
Tools • Dart 2.19.6 • DevTools 2.20.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: buildBuilding flutter applications with the toolfound in release: 3.11Found to occur in 3.11found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-engineOwned by Engine teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/flutter/flutter/issues/126261

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy