Skip to content
GitLab
Menu
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
mirror
flutter
Commits
3ea2d724
Unverified
Commit
3ea2d724
authored
2 years ago
by
Christopher Fujino
Committed by
GitHub
2 years ago
Browse files
Options
Download
Email Patches
Plain Diff
document StaticIconProvider (#120935)
document StaticIconProvider
parent
ba097e23
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/flutter/lib/src/widgets/icon_data.dart
+25
-2
packages/flutter/lib/src/widgets/icon_data.dart
with
25 additions
and
2 deletions
+25
-2
packages/flutter/lib/src/widgets/icon_data.dart
+
25
-
2
View file @
3ea2d724
...
...
@@ -8,6 +8,10 @@ import 'package:flutter/foundation.dart';
///
/// See [Icons] for a number of predefined icons available for material
/// design applications.
///
/// In release builds, the Flutter tool will tree shake out of bundled fonts
/// the code points (or instances of [IconData]) which are not referenced from
/// Dart app code. See the [staticIconProvider] annotation for more details.
@immutable
class
IconData
{
/// Creates icon data.
...
...
@@ -17,6 +21,11 @@ class IconData {
///
/// The [fontPackage] argument must be non-null when using a font family that
/// is included in a package. This is used when selecting the font.
///
/// Instantiating non-const instances of this class in your app will
/// mean the app cannot be built in release mode with icon tree-shaking (it
/// need to be explicitly opted out at build time). See [staticIconProvider]
/// for more context.
const
IconData
(
this
.
codePoint
,
{
this
.
fontFamily
,
...
...
@@ -99,6 +108,20 @@ class _StaticIconProvider {
/// Annotation for classes that only provide static const [IconData] instances.
///
/// This is a hint to the font tree shaker to ignore the constant instances
/// of [IconData] appearing in the class when tracking which code points
/// should be retained in the bundled font.
/// of [IconData] appearing in the declaration of this class when tree-shaking
/// unused code points from the bundled font.
///
/// Classes with this annotation must have only "static const" members. The
/// presence of any non-const [IconData] instances will preclude apps
/// importing the declaration into their application from being able to use
/// icon tree-shaking during release builds, resulting in larger font assets.
///
/// ```dart
/// @staticIconProvider
/// abstract final class MyCustomIcons {
/// static const String fontFamily = 'MyCustomIcons';
/// static const IconData happyFace = IconData(1, fontFamily: fontFamily);
/// static const IconData sadFace = IconData(2, fontFamily: fontFamily);
/// }
/// ```
const
Object
staticIconProvider
=
_StaticIconProvider
();
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets