mirror of
https://github.com/flutter/flutter
synced 2024-08-28 04:21:14 +00:00
Generate a demo for new icons when updating icons (#101190)
* add code to generate new icon demo and make font family optional * remove trailing spaces * Update update_icons_test.dart * remove trailing space
This commit is contained in:
parent
bc0ec85717
commit
7855132341
|
@ -40,4 +40,22 @@ void main() {
|
|||
test('no double underscores', () {
|
||||
expect(Icon.generateFlutterId('abc__123'), 'abc_123');
|
||||
});
|
||||
|
||||
test('usage string is correct', () {
|
||||
expect(
|
||||
Icon(const MapEntry<String, String>('abc', '')).usage,
|
||||
'Icon(Icons.abc),',
|
||||
);
|
||||
});
|
||||
|
||||
test('usage string is correct with replacement', () {
|
||||
expect(
|
||||
Icon(const MapEntry<String, String>('123', '')).usage,
|
||||
'Icon(Icons.onetwothree),',
|
||||
);
|
||||
expect(
|
||||
Icon(const MapEntry<String, String>('123_rounded', '')).usage,
|
||||
'Icon(Icons.onetwothree_rounded),',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ const String _defaultIconsPath = 'packages/flutter/lib/src/material/icons.dart';
|
|||
const String _defaultNewCodepointsPath = 'codepoints';
|
||||
const String _defaultOldCodepointsPath = 'bin/cache/artifacts/material_fonts/codepoints';
|
||||
const String _defaultFontFamily = 'MaterialIcons';
|
||||
const String _defaultDemoFilePath = '/tmp/new_icons_demo.dart';
|
||||
|
||||
const String _beginGeneratedMark = '// BEGIN GENERATED ICONS';
|
||||
const String _endGeneratedMark = '// END GENERATED ICONS';
|
||||
|
@ -216,7 +217,12 @@ void main(List<String> args) {
|
|||
stdout.write(newIconsContents);
|
||||
} else {
|
||||
iconsFile.writeAsStringSync(newIconsContents);
|
||||
_regenerateCodepointsFile(oldCodepointsFile, newTokenPairMap);
|
||||
|
||||
final SplayTreeMap<String, String> sortedNewTokenPairMap = SplayTreeMap<String, String>.of(newTokenPairMap);
|
||||
_regenerateCodepointsFile(oldCodepointsFile, sortedNewTokenPairMap);
|
||||
|
||||
sortedNewTokenPairMap.removeWhere((String key, String value) => oldTokenPairMap.containsKey(key));
|
||||
_generateIconDemo(File(_defaultDemoFilePath), sortedNewTokenPairMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,7 +282,7 @@ String _regenerateIconsFile(
|
|||
bool enforceSafetyChecks,
|
||||
) {
|
||||
final List<Icon> newIcons = tokenPairMap.entries
|
||||
.map((MapEntry<String, String> entry) => Icon(entry, fontFamily))
|
||||
.map((MapEntry<String, String> entry) => Icon(entry, fontFamily: fontFamily))
|
||||
.toList();
|
||||
newIcons.sort((Icon a, Icon b) => a._compareTo(b));
|
||||
|
||||
|
@ -379,18 +385,54 @@ bool testIsStable(Map<String, String> newCodepoints, Map<String, String> oldCode
|
|||
}
|
||||
}
|
||||
|
||||
void _regenerateCodepointsFile(File oldCodepointsFile, Map<String, String> newTokenPairMap) {
|
||||
void _regenerateCodepointsFile(File oldCodepointsFile, Map<String, String> tokenPairMap) {
|
||||
stderr.writeln('Regenerating old codepoints file ${oldCodepointsFile.path}');
|
||||
|
||||
final StringBuffer buf = StringBuffer();
|
||||
final SplayTreeMap<String, String> sortedNewTokenPairMap = SplayTreeMap<String, String>.of(newTokenPairMap);
|
||||
sortedNewTokenPairMap.forEach((String key, String value) => buf.writeln('$key $value'));
|
||||
tokenPairMap.forEach((String key, String value) => buf.writeln('$key $value'));
|
||||
oldCodepointsFile.writeAsStringSync(buf.toString());
|
||||
}
|
||||
|
||||
void _generateIconDemo(File demoFilePath, Map<String, String> tokenPairMap) {
|
||||
if (tokenPairMap.isEmpty) {
|
||||
stderr.writeln('No new icons, skipping generating icon demo');
|
||||
return;
|
||||
}
|
||||
stderr.writeln('Generating icon demo at $_defaultDemoFilePath');
|
||||
|
||||
final StringBuffer newIconUsages = StringBuffer();
|
||||
for (final MapEntry<String, String> entry in tokenPairMap.entries) {
|
||||
newIconUsages.writeln(Icon(entry).usage);
|
||||
}
|
||||
final String demoFileContents = '''
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() => runApp(const IconDemo());
|
||||
|
||||
class IconDemo extends StatelessWidget {
|
||||
const IconDemo({ Key? key }) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: Scaffold(
|
||||
body: Wrap(
|
||||
children: const [
|
||||
${newIconUsages.toString()}
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
''';
|
||||
demoFilePath.writeAsStringSync(demoFileContents);
|
||||
}
|
||||
|
||||
class Icon {
|
||||
// Parse tokenPair (e.g. {"6_ft_apart_outlined": "e004"}).
|
||||
Icon(MapEntry<String, String> tokenPair, this.fontFamily) {
|
||||
Icon(MapEntry<String, String> tokenPair, {this.fontFamily = _defaultFontFamily}) {
|
||||
id = tokenPair.key;
|
||||
hexCodepoint = tokenPair.value;
|
||||
|
||||
|
@ -450,6 +492,8 @@ class Icon {
|
|||
String get dartDoc =>
|
||||
'<i class="material-icons$htmlSuffix md-36">$shortId</i> — $family icon named "$name"$style';
|
||||
|
||||
String get usage => 'Icon(Icons.$flutterId),';
|
||||
|
||||
String get mirroredInRTL => _iconsMirroredWhenRTL.contains(shortId)
|
||||
? ', matchTextDirection: true'
|
||||
: '';
|
||||
|
|
Loading…
Reference in a new issue