@@ -8,6 +8,10 @@ import 'package:flutter/foundation.dart';
8
8
///
9
9
/// See [Icons] for a number of predefined icons available for material
10
10
/// design applications.
11
+ ///
12
+ /// In release builds, the Flutter tool will tree shake out of bundled fonts
13
+ /// the code points (or instances of [IconData] ) which are not referenced from
14
+ /// Dart app code. See the [staticIconProvider] annotation for more details.
11
15
@immutable
12
16
class IconData {
13
17
/// Creates icon data.
@@ -17,6 +21,11 @@ class IconData {
17
21
///
18
22
/// The [fontPackage] argument must be non-null when using a font family that
19
23
/// is included in a package. This is used when selecting the font.
24
+ ///
25
+ /// Instantiating non-const instances of this class in your app will
26
+ /// mean the app cannot be built in release mode with icon tree-shaking (it
27
+ /// need to be explicitly opted out at build time). See [staticIconProvider]
28
+ /// for more context.
20
29
const IconData (
21
30
this .codePoint, {
22
31
this .fontFamily,
@@ -99,6 +108,20 @@ class _StaticIconProvider {
99
108
/// Annotation for classes that only provide static const [IconData] instances.
100
109
///
101
110
/// This is a hint to the font tree shaker to ignore the constant instances
102
- /// of [IconData] appearing in the class when tracking which code points
103
- /// should be retained in the bundled font.
111
+ /// of [IconData] appearing in the declaration of this class when tree-shaking
112
+ /// unused code points from the bundled font.
113
+ ///
114
+ /// Classes with this annotation must have only "static const" members. The
115
+ /// presence of any non-const [IconData] instances will preclude apps
116
+ /// importing the declaration into their application from being able to use
117
+ /// icon tree-shaking during release builds, resulting in larger font assets.
118
+ ///
119
+ /// ```dart
120
+ /// @staticIconProvider
121
+ /// abstract final class MyCustomIcons {
122
+ /// static const String fontFamily = 'MyCustomIcons';
123
+ /// static const IconData happyFace = IconData(1, fontFamily: fontFamily);
124
+ /// static const IconData sadFace = IconData(2, fontFamily: fontFamily);
125
+ /// }
126
+ /// ```
104
127
const Object staticIconProvider = _StaticIconProvider ();
0 commit comments