Skip to content

Commit b03f3a7

Browse files
authored
✨ Allows not enable the image integration (#645)
## 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
1 parent e51436d commit b03f3a7

File tree

8 files changed

+164
-6
lines changed

8 files changed

+164
-6
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ flutter_gen:
147147
148148
# Optional
149149
integrations:
150+
image: true
150151
flutter_svg: true
151152
rive: true
152153
lottie: true
@@ -370,6 +371,15 @@ Widget build(BuildContext context) {
370371
371372
```
372373

374+
If you do not want to generate `AssetGenImage`, set `flutter_gen > integrations > image` to `false`.
375+
376+
```yaml
377+
# pubspec.yaml
378+
flutter_gen:
379+
integrations:
380+
image: false
381+
```
382+
373383
If you are using SVG images with [flutter_svg](https://pub.dev/packages/flutter_svg) you can use the integration feature.
374384

375385
```yaml

packages/core/lib/generators/assets_generator.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ Future<String> generateAssets(
5959
}
6060

6161
final integrations = <Integration>[
62-
ImageIntegration(
63-
config.packageParameterLiteral,
64-
parseMetadata: config.flutterGen.parseMetadata,
65-
),
62+
if (config.flutterGen.integrations.image)
63+
ImageIntegration(
64+
config.packageParameterLiteral,
65+
parseMetadata: config.flutterGen.parseMetadata,
66+
),
6667
if (config.flutterGen.integrations.flutterSvg)
6768
SvgIntegration(
6869
config.packageParameterLiteral,

packages/core/lib/settings/config_default.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ flutter_gen:
1111
1212
# Optional
1313
integrations:
14+
image: true
1415
flutter_svg: false
1516
rive: false
1617
lottie: false

packages/core/lib/settings/pubspec.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class FlutterGenFonts {
157157
@JsonSerializable()
158158
class FlutterGenIntegrations {
159159
const FlutterGenIntegrations({
160+
required this.image,
160161
required this.flutterSvg,
161162
required this.rive,
162163
required this.lottie,
@@ -165,6 +166,9 @@ class FlutterGenIntegrations {
165166
factory FlutterGenIntegrations.fromJson(Map json) =>
166167
_$FlutterGenIntegrationsFromJson(json);
167168

169+
@JsonKey(name: 'image', required: true)
170+
final bool image;
171+
168172
@JsonKey(name: 'flutter_svg', required: true)
169173
final bool flutterSvg;
170174

packages/core/lib/settings/pubspec.g.dart

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/test/assets_gen_integrations_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class TestIntegration extends Integration {
3131
void main() {
3232
group('Test Assets Integration generator', () {
3333
final resPath = p.absolute('test_resources');
34+
3435
test('Assets with No integrations on pubspec.yaml', () async {
3536
const pubspec = 'test_resources/pubspec_assets_no_integrations.yaml';
3637
const fact = 'test_resources/actual_data/assets_no_integrations.gen.dart';
@@ -40,6 +41,16 @@ void main() {
4041
await expectedAssetsGen(pubspec, generated, fact);
4142
});
4243

44+
test('Assets with no image integration', () async {
45+
const pubspec = 'test_resources/pubspec_assets_no_image_integration.yaml';
46+
const fact =
47+
'test_resources/actual_data/assets_no_image_integration.gen.dart';
48+
const generated =
49+
'test_resources/lib/gen/assets_no_image_integration.gen.dart';
50+
51+
await expectedAssetsGen(pubspec, generated, fact);
52+
});
53+
4354
test('Integration.classInstantiate', () {
4455
expect(
4556
TestIntegration().classInstantiate(

packages/core/test_resources/actual_data/assets_no_image_integration.gen.dart

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: test
2+
3+
flutter_gen:
4+
output: lib/gen/ # Optional (default: lib/gen/)
5+
line_length: 80 # Optional (default: 80)
6+
7+
integrations:
8+
image: false
9+
10+
flutter:
11+
assets:
12+
- assets/images
13+
- assets/images/chip3/chip3.jpg
14+
- assets/images/chip3/chip3.jpg # duplicated
15+
- assets/images/chip4/
16+
- assets/images/icons/fuchsia.svg
17+
- assets/images/icons/kmm.svg
18+
- assets/images/icons/paint.svg
19+
- assets/images/icons/[email protected]
20+
- assets/json/
21+
- pictures/chip5.jpg

0 commit comments

Comments
 (0)