The class IconData has a special constraints in its use due to the Flutter Icon Tree Shaker.
The constructor:
|
const IconData( |
|
this.codePoint, { |
|
this.fontFamily, |
|
this.fontPackage, |
|
this.matchTextDirection = false, |
|
this.fontFamilyFallback, |
|
}); |
The tree-shaker expects const instances with 3 specific fields with specific types:
|
Map<String, List<int>> _parseConstFinderResult(_ConstFinderResult constants) { |
|
final result = <String, List<int>>{}; |
|
for (final Map<String, Object?> iconDataMap in constants.constantInstances) { |
|
final Object? package = iconDataMap['fontPackage']; |
|
final Object? fontFamily = iconDataMap['fontFamily']; |
|
final Object? codePoint = iconDataMap['codePoint']; |
|
if ((package ?? '') is! String || (fontFamily ?? '') is! String || codePoint is! num) { |
|
throw IconTreeShakerException._( |
|
'Invalid ConstFinder result. Expected "fontPackage" to be a String, ' |
|
'"fontFamily" to be a String, and "codePoint" to be an int, ' |
|
'got: $iconDataMap.', |
|
); |
|
} |
In package:meta we have mustBeConst which will make the analyzer give warnings on non-const arguments to parameters marked with this annotation.
I propose we add the annotation to fontPackage, fontFamily, and codePoint. This will make a warning show up before running the icon-tree-shaker. Giving developers earlier feedback.
(Context: I'm working on a generalized mechanism of the icon tree shaker and underlying const finder that should give this kind of powers to a package. In the generalized mechanism it would be fine to either have const IconData(...) or IconData(const ...). The latter would be an extension of the capabilities that are today allowed by the Flutter icon tree shaker. For the generalized mechanism, we'd be suggesting people annotate their definitions with @mustBeConst for early feedback in the IDE to the users of their API.)
The class
IconDatahas a special constraints in its use due to the Flutter Icon Tree Shaker.The constructor:
flutter/packages/flutter/lib/src/widgets/icon_data.dart
Lines 47 to 53 in 995ea4d
The tree-shaker expects const instances with 3 specific fields with specific types:
flutter/packages/flutter_tools/lib/src/build_system/targets/icon_tree_shaker.dart
Lines 335 to 347 in 995ea4d
In
package:metawe havemustBeConstwhich will make the analyzer give warnings on non-const arguments to parameters marked with this annotation.I propose we add the annotation to
fontPackage,fontFamily, andcodePoint. This will make a warning show up before running the icon-tree-shaker. Giving developers earlier feedback.(Context: I'm working on a generalized mechanism of the icon tree shaker and underlying const finder that should give this kind of powers to a package. In the generalized mechanism it would be fine to either have
const IconData(...)orIconData(const ...). The latter would be an extension of the capabilities that are today allowed by the Flutter icon tree shaker. For the generalized mechanism, we'd be suggesting people annotate their definitions with@mustBeConstfor early feedback in the IDE to the users of their API.)