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
20 changes: 10 additions & 10 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
collection: ^1.16.0
crypto: ^3.0.1
glob: ^2.0.2

firebase_analytics: 9.1.8
firebase_core: 1.14.1
firebase_auth: 3.3.18
Expand Down Expand Up @@ -122,18 +122,18 @@ flutter_gen:

assets:
enabled: true
package_parameter_enabled: false
# Assets.imagesChip
# style: camel-case

# Assets.images_chip
# style: snake-case

# Assets.images.chip (default style)
# style: dot-delimiter

outputs:
class_name: MyAssets
package_parameter_enabled: false
# Assets.imagesChip
# style: camel-case

# Assets.images_chip
# style: snake-case

# Assets.images.chip (default style)
style: dot-delimiter

exclude:
- assets/images/chip3/chip3.jpg
Expand Down
91 changes: 87 additions & 4 deletions packages/core/lib/generators/assets_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AssetsGenConfig {
final List<Glob> exclude;

String get packageParameterLiteral =>
flutterGen.assets.packageParameterEnabled ? _packageName : '';
flutterGen.assets.outputs.packageParameterEnabled ? _packageName : '';
}

String generateAssets(
Expand All @@ -68,11 +68,94 @@ String generateAssets(
if (config.flutterGen.integrations.rive) RiveIntegration(),
];

if (config.flutterGen.assets.isDotDelimiterStyle) {
// TODO: This code will be removed.
// ignore: deprecated_member_use_from_same_package
final deprecatedStyle = config.flutterGen.assets.style != null;
final deprecatedPackageParam =
// ignore: deprecated_member_use_from_same_package
config.flutterGen.assets.packageParameterEnabled != null;
if (deprecatedStyle || deprecatedPackageParam) {
stderr.writeln('''

░░░░

██
██░░██
░░ ░░ ██░░░░░░██ ░░░░
██░░░░░░░░░░██
██░░░░░░░░░░██
██░░░░░░░░░░░░░░██
██░░░░░░██████░░░░░░██
██░░░░░░██████░░░░░░██
██░░░░░░░░██████░░░░░░░░██
██░░░░░░░░██████░░░░░░░░██
██░░░░░░░░░░██████░░░░░░░░░░██
██░░░░░░░░░░░░██████░░░░░░░░░░░░██
██░░░░░░░░░░░░██████░░░░░░░░░░░░██
██░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░██
██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██
██░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░██
██░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░██
██░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░░░██
░░ ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██
██████████████████████████████████████████


░░''');
}
if (deprecatedStyle && deprecatedPackageParam) {
stderr.writeln('''
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ⚠️ Warning │
│ The `style` and `package_parameter_enabled` property moved from asset to under asset.output. │
│ It should be changed in the following pubspec.yaml. │
│ https://github.com/FlutterGen/flutter_gen/pull/294 │
│ │
│ [pubspec.yaml] │
│ │
│ fluttergen: │
│ assets: │
│ outputs: │
│ style: snake-case │
│ package_parameter_enabled: true │
└────────────────────────────────────────────────────────────────────────────────────────────────┘''');
} else if (deprecatedStyle) {
stderr.writeln('''
┌───────────────────────────────────────────────────────────────────────┐
│ ⚠️ Warning │
│ The `style` property moved from asset to under asset.output. │
│ It should be changed in the following ways │
│ https://github.com/FlutterGen/flutter_gen/pull/294 │
│ │
│ [pubspec.yaml] │
│ │
│ fluttergen: │
│ assets: │
│ outputs: │
│ style: snake-case │
└───────────────────────────────────────────────────────────────────────┘''');
} else if (deprecatedPackageParam) {
stderr.writeln('''
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ ⚠️ Warning │
│ The `package_parameter_enabled` property moved from asset to under asset.output. │
│ It should be changed in the following pubspec.yaml. │
│ https://github.com/FlutterGen/flutter_gen/pull/294 │
│ │
│ [pubspec.yaml] │
│ │
│ fluttergen: │
│ assets: │
│ outputs: │
│ package_parameter_enabled: true │
└────────────────────────────────────────────────────────────────────────────────────────┘''');
}

if (config.flutterGen.assets.outputs.isDotDelimiterStyle) {
classesBuffer.writeln(_dotDelimiterStyleDefinition(config, integrations));
} else if (config.flutterGen.assets.isSnakeCaseStyle) {
} else if (config.flutterGen.assets.outputs.isSnakeCaseStyle) {
classesBuffer.writeln(_snakeCaseStyleDefinition(config, integrations));
} else if (config.flutterGen.assets.isCamelCaseStyle) {
} else if (config.flutterGen.assets.outputs.isCamelCaseStyle) {
classesBuffer.writeln(_camelCaseStyleDefinition(config, integrations));
} else {
throw 'The value of "flutter_gen/assets/style." is incorrect.';
Expand Down
4 changes: 2 additions & 2 deletions packages/core/lib/settings/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ flutter_gen:

assets:
enabled: true
package_parameter_enabled: false
style: dot-delimiter
outputs:
class_name: Assets
package_parameter_enabled: false
style: dot-delimiter
exclude: []

fonts:
Expand Down
72 changes: 47 additions & 25 deletions packages/core/lib/settings/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,45 +107,31 @@ class FlutterGenColors {

@JsonSerializable()
class FlutterGenAssets {
static const String dotDelimiterStyle = 'dot-delimiter';
static const String snakeCaseStyle = 'snake-case';
static const String camelCaseStyle = 'camel-case';

FlutterGenAssets({
required this.enabled,
required this.packageParameterEnabled,
required this.style,
this.packageParameterEnabled,
this.style,
required this.outputs,
required this.exclude,
}) {
if (style != dotDelimiterStyle &&
style != snakeCaseStyle &&
style != camelCaseStyle) {
throw ArgumentError.value(style, 'style');
}
}
});

@JsonKey(name: 'enabled', required: true)
final bool enabled;

@JsonKey(name: 'package_parameter_enabled', required: true)
final bool packageParameterEnabled;
@Deprecated('Moved to under outputs')
@JsonKey(name: 'package_parameter_enabled', required: false)
final bool? packageParameterEnabled;

@JsonKey(name: 'style', required: true)
final String style;
@Deprecated('Moved to under outputs')
@JsonKey(name: 'style', required: false)
final String? style;

@JsonKey(name: 'outputs', required: true)
final FlutterGenElementOutputs outputs;
final FlutterGenElementAssetsOutputs outputs;

@JsonKey(name: 'exclude', required: true)
final List<String> exclude;

bool get isDotDelimiterStyle => style == dotDelimiterStyle;

bool get isSnakeCaseStyle => style == snakeCaseStyle;

bool get isCamelCaseStyle => style == camelCaseStyle;

factory FlutterGenAssets.fromJson(Map json) =>
_$FlutterGenAssetsFromJson(json);
}
Expand Down Expand Up @@ -189,11 +175,47 @@ class FlutterGenIntegrations {

@JsonSerializable()
class FlutterGenElementOutputs {
FlutterGenElementOutputs({required this.className});
FlutterGenElementOutputs({
required this.className,
});

@JsonKey(name: 'class_name', required: true)
final String className;

factory FlutterGenElementOutputs.fromJson(Map json) =>
_$FlutterGenElementOutputsFromJson(json);
}

@JsonSerializable()
class FlutterGenElementAssetsOutputs extends FlutterGenElementOutputs {
static const String dotDelimiterStyle = 'dot-delimiter';
static const String snakeCaseStyle = 'snake-case';
static const String camelCaseStyle = 'camel-case';

FlutterGenElementAssetsOutputs({
required String className,
required this.packageParameterEnabled,
required this.style,
}) : super(className: className) {
if (style != dotDelimiterStyle &&
style != snakeCaseStyle &&
style != camelCaseStyle) {
throw ArgumentError.value(style, 'style');
}
}

@JsonKey(name: 'package_parameter_enabled', required: true)
final bool packageParameterEnabled;

@JsonKey(name: 'style', required: true)
final String style;

bool get isDotDelimiterStyle => style == dotDelimiterStyle;

bool get isSnakeCaseStyle => style == snakeCaseStyle;

bool get isCamelCaseStyle => style == camelCaseStyle;

factory FlutterGenElementAssetsOutputs.fromJson(Map json) =>
_$FlutterGenElementAssetsOutputsFromJson(json);
}
44 changes: 33 additions & 11 deletions packages/core/lib/settings/pubspec.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ flutter_gen:
line_length: 80 # Optional (default: 80)

assets:
style: camel-case
outputs:
style: camel-case

flutter:
assets:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ flutter_gen:
integrations:
flutter_svg: true
assets:
package_parameter_enabled: true
outputs:
package_parameter_enabled: true

flutter:
assets:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ flutter_gen:
integrations:
flutter_svg: true
assets:
package_parameter_enabled: true
outputs:
package_parameter_enabled: true

flutter:
assets:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ flutter_gen:
line_length: 80 # Optional (default: 80)

assets:
style: snake-case
outputs:
style: snake-case

flutter:
assets:
Expand Down