Browse Source

Merge pull request #34 from jld3103/feature/tree-shake-icons

file_icons: Make it possible to build apps with icon tree shaking enabled
pull/20/head
jld3103 2 years ago committed by GitHub
parent
commit
bf79cc1209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      packages/file_icons/bin/file_icons.dart
  2. 6
      packages/file_icons/lib/file_icons.dart
  3. 3498
      packages/file_icons/lib/src/data.dart
  4. 6
      packages/file_icons/lib/src/meta.dart

15
packages/file_icons/bin/file_icons.dart

@ -95,6 +95,7 @@ void generateData() {
'// THIS CODE IS GENERATED - DO NOT EDIT MANUALLY',
'',
"import 'package:file_icons/src/meta.dart';",
"import 'package:flutter/widgets.dart';",
'',
'// Code points',
// This filters unused codepoints.
@ -108,13 +109,23 @@ void generateData() {
'const ${_toVariableName(colorName)} = ${colors[colorName]};',
],
'',
'/// Mapping between file extensions and code points and colors',
"const _fontFamily = 'Seti';",
"const _fontPackage = 'file_icons';",
'',
'/// Mapping between file extensions and [IconData] and color',
'const iconSetMap = {',
// This filters icons where the code points are missing. That indicates the fonts in seti-ui are not up-to-date.
// Run `gulp icons` in the seti-ui repository and everything should be there.
// Please submit the changes upstream if you can.
for (final pattern in iconSet.keys.where((final pattern) => codePoints.keys.contains(iconSet[pattern]![0]))) ...[
" '$pattern': SetiMeta(${_toVariableName(iconSet[pattern]![0])}, ${_toVariableName(iconSet[pattern]![1])}),",
" '$pattern': SetiMeta(",
' IconData(',
' ${_toVariableName(iconSet[pattern]![0])},',
' fontFamily: _fontFamily,',
' fontPackage: _fontPackage,',
' ),',
' ${_toVariableName(iconSet[pattern]![1])},',
' ),',
],
'};',
'',

6
packages/file_icons/lib/file_icons.dart

@ -40,11 +40,7 @@ class FileIcon extends StatelessWidget {
final meta = iconSetMap[key ?? '.txt']!;
return Icon(
IconData(
meta.codePoint,
fontFamily: 'Seti',
fontPackage: 'file_icons',
),
meta.iconData,
color: color ?? Color(meta.color),
size: size,
);

3498
packages/file_icons/lib/src/data.dart

File diff suppressed because it is too large Load Diff

6
packages/file_icons/lib/src/meta.dart

@ -1,9 +1,11 @@
import 'package:flutter/widgets.dart';
// ignore: public_member_api_docs
class SetiMeta {
// ignore: public_member_api_docs
const SetiMeta(this.codePoint, this.color);
const SetiMeta(this.iconData, this.color);
// ignore: public_member_api_docs
final int codePoint;
final IconData iconData;
// ignore: public_member_api_docs
final int color;
}

Loading…
Cancel
Save