Skip to content

Commit

Permalink
✨ Allows not enable the image integration (#645)
Browse files Browse the repository at this point in the history
## What does this change?

Adds the explicit and configurable image integration.

Resolves #636 🎯

## Type of change

- [x] New feature (non-breaking change which adds functionality)
- [x] This change requires a documentation update
  • Loading branch information
AlexV525 authored Jan 29, 2025
1 parent e51436d commit b03f3a7
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 6 deletions.
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

0 comments on commit b03f3a7

Please sign in to comment.