forceCompileTimeTreeShaking static method
This routine exists to FORCE TREE SHAKING of the icon fonts that may not be referenced at all within the application. This is required because the Material Symbols Icons have 3 font varieties and it is very likely only one will be used. Tree shaking DOES NOT OCCUR for fonts that are never referenced, so having a this method FORCES a reference to the fonts - and invokes tree shaking for each of the three fonts. In this way any unused fonts are reduced to around 2k, which the icon tree shake will report as 100.0% reduction. (Tree shaking occurs when a const declaration to an IconData() class occurs.)
NOTE: VERY IMPORTANT - the @pargma('vm:entry-point')
annotation is REQUIRED
and it is being used to force the dart compilation process to believe that this
method is required and that it CAN NOT tree-shake this method when it never
finds a call to it in the dart source code.
Implementation
@pragma('vm:entry-point')
static void forceCompileTimeTreeShaking() {
// these variables must be declared as var to trigger tree shaking, when declared as const
// then the tree shaking is not triggered. These are references to the 'check_indeterminate_small'
// icon in each of the fonts (one of the smallest glyphs we can include).
// ignore: unused_local_variable
var forceOutlinedTreeShake = const IconData(0xf88a,
fontFamily: 'MaterialSymbolsOutlined',
fontPackage: 'material_symbols_icons');
// ignore: unused_local_variable
var forceRoundedTreeShake = const IconData(0xf88a,
fontFamily: 'MaterialSymbolsRounded',
fontPackage: 'material_symbols_icons');
// ignore: unused_local_variable
var forceSharpTreeShake = const IconData(0xf88a,
fontFamily: 'MaterialSymbolsSharp',
fontPackage: 'material_symbols_icons');
}