Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Allows not enable the image integration #645

Merged
merged 3 commits into from
Jan 29, 2025
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ flutter_gen:

# Optional
integrations:
image: true
flutter_svg: true
rive: true
lottie: true
Expand Down Expand Up @@ -370,6 +371,15 @@ Widget build(BuildContext context) {

```

If you do not want to generate `AssetGenImage`, set `flutter_gen > integrations > image` to `false`.

```yaml
# pubspec.yaml
flutter_gen:
integrations:
image: false
```

If you are using SVG images with [flutter_svg](https://pub.dev/packages/flutter_svg) you can use the integration feature.

```yaml
Expand Down
9 changes: 5 additions & 4 deletions packages/core/lib/generators/assets_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ Future<String> generateAssets(
}

final integrations = <Integration>[
ImageIntegration(
config.packageParameterLiteral,
parseMetadata: config.flutterGen.parseMetadata,
),
if (config.flutterGen.integrations.image)
ImageIntegration(
config.packageParameterLiteral,
parseMetadata: config.flutterGen.parseMetadata,
),
if (config.flutterGen.integrations.flutterSvg)
SvgIntegration(
config.packageParameterLiteral,
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/settings/config_default.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ flutter_gen:
# Optional
integrations:
image: true
flutter_svg: false
rive: false
lottie: false
Expand Down
4 changes: 4 additions & 0 deletions packages/core/lib/settings/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class FlutterGenFonts {
@JsonSerializable()
class FlutterGenIntegrations {
const FlutterGenIntegrations({
required this.image,
required this.flutterSvg,
required this.rive,
required this.lottie,
Expand All @@ -165,6 +166,9 @@ class FlutterGenIntegrations {
factory FlutterGenIntegrations.fromJson(Map json) =>
_$FlutterGenIntegrationsFromJson(json);

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

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

Expand Down
5 changes: 3 additions & 2 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.

11 changes: 11 additions & 0 deletions packages/core/test/assets_gen_integrations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TestIntegration extends Integration {
void main() {
group('Test Assets Integration generator', () {
final resPath = p.absolute('test_resources');

test('Assets with No integrations on pubspec.yaml', () async {
const pubspec = 'test_resources/pubspec_assets_no_integrations.yaml';
const fact = 'test_resources/actual_data/assets_no_integrations.gen.dart';
Expand All @@ -40,6 +41,16 @@ void main() {
await expectedAssetsGen(pubspec, generated, fact);
});

test('Assets with no image integration', () async {
const pubspec = 'test_resources/pubspec_assets_no_image_integration.yaml';
const fact =
'test_resources/actual_data/assets_no_image_integration.gen.dart';
const generated =
'test_resources/lib/gen/assets_no_image_integration.gen.dart';

await expectedAssetsGen(pubspec, generated, fact);
});

test('Integration.classInstantiate', () {
expect(
TestIntegration().classInstantiate(
Expand Down

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
@@ -0,0 +1,21 @@
name: test

flutter_gen:
output: lib/gen/ # Optional (default: lib/gen/)
line_length: 80 # Optional (default: 80)

integrations:
image: false

flutter:
assets:
- assets/images
- assets/images/chip3/chip3.jpg
- assets/images/chip3/chip3.jpg # duplicated
- assets/images/chip4/
- assets/images/icons/fuchsia.svg
- assets/images/icons/kmm.svg
- assets/images/icons/paint.svg
- assets/images/icons/dart@test.svg
- assets/json/
- pictures/chip5.jpg