Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions example/lib/gen/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,72 +14,100 @@ import 'package:flare_flutter/flare_controller.dart';
class $PicturesGen {
const $PicturesGen();

/// File path: pictures/chip5.jpg
AssetGenImage get chip5 => const AssetGenImage('pictures/chip5.jpg');
}

class $AssetsFlareGen {
const $AssetsFlareGen();

/// File path: assets/flare/Penguin.flr
FlareGenImage get penguin => const FlareGenImage('assets/flare/Penguin.flr');
}

class $AssetsImagesGen {
const $AssetsImagesGen();

/// File path: assets/images/chip1.jpg
AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg');

/// File path: assets/images/chip2.jpg
AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');

$AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen();
$AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen();
$AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen();

/// File path: assets/images/logo.png
AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');

/// File path: assets/images/profile.jpg
AssetGenImage get profileJpg =>
const AssetGenImage('assets/images/profile.jpg');

/// File path: assets/images/profile.png
AssetGenImage get profilePng =>
const AssetGenImage('assets/images/profile.png');
}

class $AssetsJsonGen {
const $AssetsJsonGen();

/// File path: assets/json/fruits.json
String get fruits => 'assets/json/fruits.json';
}

class $AssetsMovieGen {
const $AssetsMovieGen();

/// File path: assets/movie/the_earth.mp4
String get theEarth => 'assets/movie/the_earth.mp4';
}

class $AssetsUnknownGen {
const $AssetsUnknownGen();

/// File path: assets/unknown/CHANGELOG.md
String get changelog => 'assets/unknown/CHANGELOG.md';

/// File path: assets/unknown/README.md
String get readme => 'assets/unknown/README.md';

/// File path: assets/unknown/unknown_mime_type.bk
String get unknownMimeType => 'assets/unknown/unknown_mime_type.bk';
}

class $AssetsImagesChip3Gen {
const $AssetsImagesChip3Gen();

/// File path: assets/images/chip3/chip3.jpg
AssetGenImage get chip3 =>
const AssetGenImage('assets/images/chip3/chip3.jpg');
}

class $AssetsImagesChip4Gen {
const $AssetsImagesChip4Gen();

/// File path: assets/images/chip4/chip4.jpg
AssetGenImage get chip4 =>
const AssetGenImage('assets/images/chip4/chip4.jpg');
}

class $AssetsImagesIconsGen {
const $AssetsImagesIconsGen();

/// File path: assets/images/icons/dart@test.svg
SvgGenImage get dartTest =>
const SvgGenImage('assets/images/icons/dart@test.svg');

/// File path: assets/images/icons/fuchsia.svg
SvgGenImage get fuchsia =>
const SvgGenImage('assets/images/icons/fuchsia.svg');

/// File path: assets/images/icons/kmm.svg
SvgGenImage get kmm => const SvgGenImage('assets/images/icons/kmm.svg');

/// File path: assets/images/icons/paint.svg
SvgGenImage get paint => const SvgGenImage('assets/images/icons/paint.svg');
}

Expand Down
45 changes: 45 additions & 0 deletions example/lib/gen/colors.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,32 @@ import 'package:flutter/material.dart';
class ColorName {
ColorName._();

/// Color: #000000
static const Color black = Color(0xFF000000);

/// Color: #4D000000
static const Color black30 = Color(0x4D000000);

/// Color: #66000000
static const Color black40 = Color(0x66000000);

/// Color: #80000000
static const Color black50 = Color(0x80000000);

/// Color: #99000000
static const Color black60 = Color(0x99000000);

/// MaterialColor:
/// 50: #FFF9E5E5
/// 100: #FFF1BFBF
/// 200: #FFE79595
/// 300: #FFDD6A6A
/// 400: #FFD64A4A
/// 500: #FFCF2A2A
/// 600: #FFCA2525
/// 700: #FFC31F1F
/// 800: #FFBD1919
/// 900: #FFB20F0F
static const MaterialColor crimsonRed = MaterialColor(
0xFFCF2A2A,
<int, Color>{
Expand All @@ -31,9 +52,27 @@ class ColorName {
900: Color(0xFFB20F0F),
},
);

/// Color: #979797
static const Color gray410 = Color(0xFF979797);

/// Color: #EEEEEE
static const Color gray70 = Color(0xFFEEEEEE);

/// Color: #FFFFFF
static const Color white = Color(0xFFFFFFFF);

/// MaterialColor:
/// 50: #FFFBF2E5
/// 100: #FFF5DFBE
/// 200: #FFEFCA93
/// 300: #FFE9B568
/// 400: #FFE4A547
/// 500: #FFDF9527
/// 600: #FFDB8D23
/// 700: #FFD7821D
/// 800: #FFD27817
/// 900: #FFCA670E
static const MaterialColor yellowOcher = MaterialColor(
0xFFDF9527,
<int, Color>{
Expand All @@ -49,6 +88,12 @@ class ColorName {
900: Color(0xFFCA670E),
},
);

/// MaterialAccentColor:
/// 100: #FFFFE8E0
/// 200: #FFFFBCA3
/// 400: #FFFFA989
/// 700: #FFFF9E7A
static const MaterialAccentColor yellowOcherAccent = MaterialAccentColor(
0xFFFFBCA3,
<int, Color>{
Expand Down
3 changes: 3 additions & 0 deletions example/lib/gen/fonts.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
class FontFamily {
FontFamily._();

/// Font family: Raleway
static const String raleway = 'Raleway';

/// Font family: RobotoMono
static const String robotoMono = 'RobotoMono';
}
46 changes: 39 additions & 7 deletions packages/core/lib/generators/assets_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,21 @@ _Statement? _createAssetTypeStatement(
if (assetType.isSupportedImage) {
return _Statement(
type: 'AssetGenImage',
filePath: assetType.path,
name: name,
value: 'AssetGenImage(\'${posixStyle(assetType.path)}\')',
isConstConstructor: true,
needDartDoc: true,
);
} else if (FileSystemEntity.isDirectorySync(childAssetAbsolutePath)) {
final childClassName = '\$${assetType.path.camelCase().capitalize()}Gen';
return _Statement(
type: childClassName,
filePath: assetType.path,
name: name,
value: '$childClassName()',
isConstConstructor: true,
needDartDoc: false,
);
} else if (!assetType.isIgnoreFile) {
final integration = integrations.firstWhereOrNull(
Expand All @@ -166,17 +170,21 @@ _Statement? _createAssetTypeStatement(
if (integration == null) {
return _Statement(
type: 'String',
filePath: assetType.path,
name: name,
value: '\'${posixStyle(assetType.path)}\'',
isConstConstructor: false,
needDartDoc: true,
);
} else {
integration.isEnabled = true;
return _Statement(
type: integration.className,
filePath: assetType.path,
name: name,
value: integration.classInstantiate(posixStyle(assetType.path)),
isConstConstructor: integration.isConstConstructor,
needDartDoc: true,
);
}
}
Expand Down Expand Up @@ -226,17 +234,20 @@ String _dotDelimiterStyleDefinition(
if (dirname(assetType.path) == '.') {
assetsStaticStatements.add(_Statement(
type: className,
filePath: assetType.path,
name: assetType.baseName.camelCase(),
value: '$className()',
isConstConstructor: true,
needDartDoc: true,
));
}
}

assetTypeQueue.addAll(assetType.children);
}
}
buffer.writeln(_assetsClassDefinition(assetsStaticStatements));
buffer
.writeln(_dotDelimiterStyleAssetsClassDefinition(assetsStaticStatements));
return buffer.toString();
}

Expand Down Expand Up @@ -292,13 +303,24 @@ String _flatStyleDefinition(
)
.whereType<_Statement>()
.toList();
return _assetsClassDefinition(statements);
return _flatStyleAssetsClassDefinition(statements);
}

String _assetsClassDefinition(List<_Statement> statements) {
final statementsBlock = statements
.map((statement) => ' ${statement.toStaticFieldString()}')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unnecessary because of using DartFormatter.

.join('\n');
String _flatStyleAssetsClassDefinition(List<_Statement> statements) {
final statementsBlock =
statements.map((statement) => '''${statement.toDartDocString()}
${statement.toStaticFieldString()}
''').join('\n');
return _assetsClassDefinition(statementsBlock);
}

String _dotDelimiterStyleAssetsClassDefinition(List<_Statement> statements) {
final statementsBlock =
statements.map((statement) => statement.toStaticFieldString()).join('\n');
return _assetsClassDefinition(statementsBlock);
}

String _assetsClassDefinition(String statementsBlock) {
return '''
class Assets {
Assets._();
Expand All @@ -313,7 +335,11 @@ String _directoryClassGenDefinition(
List<_Statement> statements,
) {
final statementsBlock = statements
.map((statement) => ' ${statement.toGetterString()}')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unnecessary because of using DartFormatter.

.map((statement) => statement.needDartDoc
? '''${statement.toDartDocString()}
${statement.toGetterString()}
'''
: statement.toGetterString())
.join('\n');
return '''
class $className {
Expand Down Expand Up @@ -383,15 +409,21 @@ class AssetGenImage extends AssetImage {
class _Statement {
const _Statement({
required this.type,
required this.filePath,
required this.name,
required this.value,
required this.isConstConstructor,
required this.needDartDoc,
});

final String type;
final String filePath;
final String name;
final String value;
final bool isConstConstructor;
final bool needDartDoc;

String toDartDocString() => '/// File path: $filePath';

String toGetterString() =>
'$type get $name => ${isConstConstructor ? 'const' : ''} $value;';
Expand Down
15 changes: 10 additions & 5 deletions packages/core/lib/generators/colors_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ String generateColors(
buffer.writeln("import 'package:flutter/material.dart';");
buffer.writeln();
buffer.writeln('class ColorName {');
buffer.writeln(' ColorName._();');
buffer.writeln('ColorName._();');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unnecessary because of using DartFormatter.

buffer.writeln();

final colorList = <_Color>[];
Expand Down Expand Up @@ -61,8 +61,9 @@ String _colorStatement(_Color color) {
final buffer = StringBuffer();
if (color.isMaterial) {
final swatch = swatchFromPrimaryHex(color.hex);
final statement = '''
static const MaterialColor ${color.name.camelCase()} = MaterialColor(
final statement = '''/// MaterialColor:
${swatch.entries.map((e) => '/// ${e.key}: ${hexFromColor(e.value)}').join('\n')}
static const MaterialColor ${color.name.camelCase()} = MaterialColor(
${swatch[500]},
<int, Color>{
${swatch.entries.map((e) => '${e.key}: Color(${e.value}),').join('\n')}
Expand All @@ -72,8 +73,9 @@ String _colorStatement(_Color color) {
}
if (color.isMaterialAccent) {
final accentSwatch = accentSwatchFromPrimaryHex(color.hex);
final statement = '''
static const MaterialAccentColor ${color.name.camelCase()}Accent = MaterialAccentColor(
final statement = '''/// MaterialAccentColor:
${accentSwatch.entries.map((e) => '/// ${e.key}: ${hexFromColor(e.value)}').join('\n')}
static const MaterialAccentColor ${color.name.camelCase()}Accent = MaterialAccentColor(
${accentSwatch[200]},
<int, Color>{
${accentSwatch.entries.map((e) => '${e.key}: Color(${e.value}),').join('\n')}
Expand All @@ -82,8 +84,11 @@ String _colorStatement(_Color color) {
buffer.writeln(statement);
}
if (color.isNormal) {
final comment = '/// Color: ${color.hex}';
final statement =
'''static const Color ${color.name.camelCase()} = Color(${colorFromHex(color.hex)});''';

buffer.writeln(comment);
buffer.writeln(statement);
}
return buffer.toString();
Expand Down
5 changes: 3 additions & 2 deletions packages/core/lib/generators/fonts_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ String generateFonts(
buffer.writeln(header);
buffer.writeln(ignoreAnalysis);
buffer.writeln('class FontFamily {');
buffer.writeln(' FontFamily._();');
buffer.writeln('FontFamily._();');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unnecessary because of using DartFormatter.

buffer.writeln();

fonts.map((element) => element.family).distinct().sorted().forEach((family) {
buffer.writeln(" static const String ${family.camelCase()} = '$family';");
buffer.writeln("""/// Font family: $family
static const String ${family.camelCase()} = '$family';""");
});

buffer.writeln('}');
Expand Down
6 changes: 6 additions & 0 deletions packages/core/lib/utils/color.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import 'package:color/color.dart';

/// e.g. 0xBB1122 -> #BB1122
String hexFromColor(String hexColor) {
return hexColor.replaceFirst('0x', '#').toUpperCase();
}

/// e.g. #BB1122 -> FFBB1122
String colorFromHex(String hexColor) {
hexColor = hexColor.toUpperCase().replaceFirst('#', '');
if (hexColor.length == 6) {
Expand Down
Loading