In a mobile application I'm trying to construct material icons based on icon data point obtained from server, here's a minimal version of the conflicting code
class CustomIconFactory {
static CustomIconFactory createIcon(IconParameters parameters) {
Widget widget = Icon(
IconData(
parameters.iconId,
fontFamily: "MaterialIcons"
),
color: Color(parameters.colorId),
);
// more logic here
return CustomIcon(
baseIcon,
// more optional parameters here
);
}
}
when executing flutter build apk
, I get the following error
This application cannot tree shake icons fonts. It has non-constant instances of IconData at the following locations:
- file:///C:/Users/Admin/Desktop/mobile_application/ips-mobile-application/lib/power_animation/data_structures/power_flow_animation_parameters.dart:44:7
Target aot_android_asset_bundle failed: Exception: Avoid non-constant invocations of IconData or try to build again with --no-tree-shake-icons.
I don't know why, although other parts of the code use similar approach with no problems (inside a static method, and having the icon code point extracted from a parameter class).
thanks in advance