@@ -122,6 +122,9 @@ $ flutter packages pub run build_runner build
122
122
flutter_gen :
123
123
output : lib/gen/ # Optional (default: lib/gen/)
124
124
lineLength : 80 # Optional (default: 80)
125
+
126
+ integrations :
127
+ flutter_svg : true
125
128
126
129
colors :
127
130
inputs :
@@ -191,9 +194,33 @@ Widget build(BuildContext context) {
191
194
192
195
` ` `
193
196
197
+ If you are using SVG images with flutter_svg you can use the integration feature.
198
+
199
+ ` ` ` yaml
200
+ # pubspec.yaml
201
+ flutter_gen:
202
+
203
+ integrations:
204
+ flutter_svg: true
205
+
206
+ flutter:
207
+ assets:
208
+ - assets/json/fruits.json
209
+ ` ` `
210
+
211
+ ` ` ` dart
212
+ Widget build(BuildContext context) {
213
+ return Assets.images.icons.paint.svg(
214
+ width: 120,
215
+ height: 120
216
+ );
217
+ }
218
+ ` ` `
219
+
194
220
In other cases, the asset is generated as String class.
195
221
196
222
` ` ` dart
223
+ // If don't use the Integrations.
197
224
final svg = SvgPicture.asset(Assets.images.icons.paint);
198
225
199
226
final json = await rootBundle.loadString(Assets.json.fruits);
@@ -219,6 +246,63 @@ pictures/ocean_view.jpg => Assets.pictures.oceanView
219
246
/// *****************************************************
220
247
221
248
import 'package:flutter/widgets.dart';
249
+ import 'package:flutter_svg/flutter_svg.dart';
250
+ import 'package:flutter/services.dart';
251
+
252
+ class $PicturesGen {
253
+ const $PicturesGen();
254
+
255
+ AssetGenImage get chip5 => const AssetGenImage('pictures/chip5.jpg');
256
+ }
257
+
258
+ class $AssetsImagesGen {
259
+ const $AssetsImagesGen();
260
+
261
+ AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');
262
+ AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg');
263
+ AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
264
+ AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg');
265
+ $AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen();
266
+ $AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen();
267
+ $AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen();
268
+ }
269
+
270
+ class $AssetsJsonGen {
271
+ const $AssetsJsonGen();
272
+
273
+ String get fruits => 'assets/json/fruits.json';
274
+ }
275
+
276
+ class $AssetsImagesChip3Gen {
277
+ const $AssetsImagesChip3Gen();
278
+
279
+ AssetGenImage get chip3 =>
280
+ const AssetGenImage('assets/images/chip3/chip3.jpg');
281
+ }
282
+
283
+ class $AssetsImagesChip4Gen {
284
+ const $AssetsImagesChip4Gen();
285
+
286
+ AssetGenImage get chip4 =>
287
+ const AssetGenImage('assets/images/chip4/chip4.jpg');
288
+ }
289
+
290
+ class $AssetsImagesIconsGen {
291
+ const $AssetsImagesIconsGen();
292
+
293
+ SvgGenImage get fuchsia =>
294
+ const SvgGenImage('assets/images/icons/fuchsia.svg');
295
+ SvgGenImage get kmm => const SvgGenImage('assets/images/icons/kmm.svg');
296
+ SvgGenImage get paint => const SvgGenImage('assets/images/icons/paint.svg');
297
+ }
298
+
299
+ class Assets {
300
+ Assets._();
301
+
302
+ static const $AssetsImagesGen images = $AssetsImagesGen();
303
+ static const $AssetsJsonGen json = $AssetsJsonGen();
304
+ static const $PicturesGen pictures = $PicturesGen();
305
+ }
222
306
223
307
class AssetGenImage extends AssetImage {
224
308
const AssetGenImage(String assetName)
@@ -270,57 +354,36 @@ class AssetGenImage extends AssetImage {
270
354
String get path => _assetName;
271
355
}
272
356
273
- class $PicturesGen {
274
- const $PicturesGen();
275
-
276
- AssetGenImage get chip5 => const AssetGenImage('pictures/chip5.jpg');
277
- }
278
-
279
- class $AssetsImagesGen {
280
- const $AssetsImagesGen();
281
-
282
- AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');
283
- AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg');
284
- AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
285
- AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg');
286
- $AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen();
287
- $AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen();
288
- $AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen();
289
- }
290
-
291
- class $AssetsJsonGen {
292
- const $AssetsJsonGen();
293
-
294
- String get fruits => 'assets/json/fruits.json';
295
- }
296
-
297
- class $AssetsImagesChip3Gen {
298
- const $AssetsImagesChip3Gen();
357
+ class SvgGenImage {
358
+ const SvgGenImage(this._assetName);
299
359
300
- AssetGenImage get chip3 =>
301
- const AssetGenImage('assets/images/chip3/chip3.jpg');
302
- }
303
-
304
- class $AssetsImagesChip4Gen {
305
- const $AssetsImagesChip4Gen();
306
-
307
- AssetGenImage get chip4 =>
308
- const AssetGenImage('assets/images/chip4/chip4.jpg');
309
- }
360
+ final String _assetName;
310
361
311
- class $AssetsImagesIconsGen {
312
- const $AssetsImagesIconsGen();
362
+ SvgPicture svg({
363
+ bool matchTextDirection = false,
364
+ AssetBundle bundle,
365
+ String package,
366
+ double width,
367
+ double height,
368
+ BoxFit fit = BoxFit.contain,
369
+ AlignmentGeometry alignment = Alignment.center,
370
+ bool allowDrawingOutsideViewBox = false,
371
+ WidgetBuilder placeholderBuilder,
372
+ Color color,
373
+ BlendMode colorBlendMode = BlendMode.srcIn,
374
+ String semanticsLabel,
375
+ bool excludeFromSemantics = false,
376
+ Clip clipBehavior = Clip.hardEdge,
377
+ }) {
378
+ return SvgPicture.asset(
379
+ _assetName,
380
+ matchTextDirection: matchTextDirection,
381
+ );
382
+ }
313
383
314
- String get paint => 'assets/images/icons/paint.svg' ;
384
+ String get path => _assetName ;
315
385
}
316
386
317
- class Assets {
318
- Assets._();
319
-
320
- static const $AssetsImagesGen images = $AssetsImagesGen();
321
- static const $AssetsJsonGen json = $AssetsJsonGen();
322
- static const $PicturesGen pictures = $PicturesGen();
323
- }
324
387
```
325
388
326
389
</p >
0 commit comments