Skip to content

Commit 993eb80

Browse files
author
Rami AlDhafeeri
committed
make minor changes
1 parent ad4f9bc commit 993eb80

File tree

9 files changed

+120
-127
lines changed

9 files changed

+120
-127
lines changed

examples/example/lib/gen/assets.gen.dart

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import 'package:flutter/widgets.dart';
1111
import 'package:flutter_svg/flutter_svg.dart';
1212
import 'package:flutter/services.dart';
13-
import 'package:vector_graphics/vector_graphics.dart';
1413
import 'package:flare_flutter/flare_actor.dart';
1514
import 'package:flare_flutter/flare_controller.dart';
1615
import 'package:rive/rive.dart';
@@ -35,10 +34,7 @@ class $AssetsImagesGen {
3534
/// File path: assets/images/chip2.jpg
3635
AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');
3736

38-
/// Directory path: assets/images/chip4
3937
$AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen();
40-
41-
/// Directory path: assets/images/icons
4238
$AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen();
4339

4440
/// File path: assets/images/logo.png
@@ -85,7 +81,6 @@ class $AssetsLottieGen {
8581
LottieGenImage get hamburgerArrow =>
8682
const LottieGenImage('assets/lottie/hamburger_arrow.json');
8783

88-
/// Directory path: assets/lottie/wrong
8984
$AssetsLottieWrongGen get wrong => const $AssetsLottieWrongGen();
9085

9186
/// List of all assets
@@ -187,7 +182,6 @@ class $AssetsLottieWrongGen {
187182
class MyAssets {
188183
MyAssets._();
189184

190-
static const String readme = 'README.md';
191185
static const $AssetsFlareGen flare = $AssetsFlareGen();
192186
static const $AssetsImagesGen images = $AssetsImagesGen();
193187
static const $AssetsJsonGen json = $AssetsJsonGen();
@@ -196,18 +190,13 @@ class MyAssets {
196190
static const $AssetsMovieGen movie = $AssetsMovieGen();
197191
static const $AssetsRiveGen rive = $AssetsRiveGen();
198192
static const $AssetsUnknownGen unknown = $AssetsUnknownGen();
199-
200-
/// List of all assets
201-
static List<String> get values => [readme];
202193
}
203194

204195
class AssetGenImage {
205-
const AssetGenImage(this._assetName, {this.size = null});
196+
const AssetGenImage(this._assetName);
206197

207198
final String _assetName;
208199

209-
final Size? size;
210-
211200
Image image({
212201
Key? key,
213202
AssetBundle? bundle,
@@ -278,16 +267,10 @@ class AssetGenImage {
278267
}
279268

280269
class SvgGenImage {
281-
const SvgGenImage(this._assetName,
282-
{this.size = null, this.isVecFormat = false});
283-
const SvgGenImage.vec(this._assetName,
284-
{this.size = null, this.isVecFormat = true});
270+
const SvgGenImage(this._assetName);
285271

286272
final String _assetName;
287273

288-
final Size? size;
289-
final bool isVecFormat;
290-
291274
SvgPicture svg({
292275
Key? key,
293276
bool matchTextDirection = false,
@@ -308,15 +291,12 @@ class SvgGenImage {
308291
@deprecated BlendMode colorBlendMode = BlendMode.srcIn,
309292
@deprecated bool cacheColorFilter = false,
310293
}) {
311-
return SvgPicture(
312-
switch (isVecFormat) {
313-
true => AssetBytesLoader(_assetName,
314-
assetBundle: bundle, packageName: package),
315-
false =>
316-
SvgAssetLoader(_assetName, assetBundle: bundle, packageName: package),
317-
},
294+
return SvgPicture.asset(
295+
_assetName,
318296
key: key,
319297
matchTextDirection: matchTextDirection,
298+
bundle: bundle,
299+
package: package,
320300
width: width,
321301
height: height,
322302
fit: fit,
@@ -326,8 +306,9 @@ class SvgGenImage {
326306
semanticsLabel: semanticsLabel,
327307
excludeFromSemantics: excludeFromSemantics,
328308
theme: theme,
329-
colorFilter: colorFilter ??
330-
(color == null ? null : ColorFilter.mode(color, colorBlendMode)),
309+
colorFilter: colorFilter,
310+
color: color,
311+
colorBlendMode: colorBlendMode,
331312
clipBehavior: clipBehavior,
332313
cacheColorFilter: cacheColorFilter,
333314
);
@@ -394,7 +375,6 @@ class RiveGenImage {
394375
Alignment? alignment,
395376
Widget? placeHolder,
396377
bool antialiasing = true,
397-
bool useArtboardSize = false,
398378
List<RiveAnimationController> controllers = const [],
399379
OnInitCallback? onInit,
400380
}) {
@@ -407,7 +387,6 @@ class RiveGenImage {
407387
alignment: alignment,
408388
placeHolder: placeHolder,
409389
antialiasing: antialiasing,
410-
useArtboardSize: useArtboardSize,
411390
controllers: controllers,
412391
onInit: onInit,
413392
);

examples/example_resources/lib/gen/assets.gen.dart

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import 'package:flutter/widgets.dart';
1111
import 'package:flutter_svg/flutter_svg.dart';
1212
import 'package:flutter/services.dart';
13-
import 'package:vector_graphics/vector_graphics.dart';
1413
import 'package:flare_flutter/flare_actor.dart';
1514
import 'package:flare_flutter/flare_controller.dart';
1615
import 'package:rive/rive.dart';
@@ -63,14 +62,12 @@ class ResAssets {
6362
}
6463

6564
class AssetGenImage {
66-
const AssetGenImage(this._assetName, {this.size = null});
65+
const AssetGenImage(this._assetName);
6766

6867
final String _assetName;
6968

7069
static const String package = 'example_resources';
7170

72-
final Size? size;
73-
7471
Image image({
7572
Key? key,
7673
AssetBundle? bundle,
@@ -143,18 +140,12 @@ class AssetGenImage {
143140
}
144141

145142
class SvgGenImage {
146-
const SvgGenImage(this._assetName,
147-
{this.size = null, this.isVecFormat = false});
148-
const SvgGenImage.vec(this._assetName,
149-
{this.size = null, this.isVecFormat = true});
143+
const SvgGenImage(this._assetName);
150144

151145
final String _assetName;
152146

153147
static const String package = 'example_resources';
154148

155-
final Size? size;
156-
final bool isVecFormat;
157-
158149
SvgPicture svg({
159150
Key? key,
160151
bool matchTextDirection = false,
@@ -169,22 +160,19 @@ class SvgGenImage {
169160
WidgetBuilder? placeholderBuilder,
170161
String? semanticsLabel,
171162
bool excludeFromSemantics = false,
172-
SvgTheme? theme,
163+
SvgTheme theme = const SvgTheme(),
173164
ColorFilter? colorFilter,
174165
Clip clipBehavior = Clip.hardEdge,
175166
@deprecated Color? color,
176167
@deprecated BlendMode colorBlendMode = BlendMode.srcIn,
177168
@deprecated bool cacheColorFilter = false,
178169
}) {
179-
return SvgPicture(
180-
switch (isVecFormat) {
181-
true => AssetBytesLoader(_assetName,
182-
assetBundle: bundle, packageName: package),
183-
false =>
184-
SvgAssetLoader(_assetName, assetBundle: bundle, packageName: package),
185-
},
170+
return SvgPicture.asset(
171+
_assetName,
186172
key: key,
187173
matchTextDirection: matchTextDirection,
174+
bundle: bundle,
175+
package: package,
188176
width: width,
189177
height: height,
190178
fit: fit,
@@ -194,8 +182,9 @@ class SvgGenImage {
194182
semanticsLabel: semanticsLabel,
195183
excludeFromSemantics: excludeFromSemantics,
196184
theme: theme,
197-
colorFilter: colorFilter ??
198-
(color == null ? null : ColorFilter.mode(color, colorBlendMode)),
185+
colorFilter: colorFilter,
186+
color: color,
187+
colorBlendMode: colorBlendMode,
199188
clipBehavior: clipBehavior,
200189
cacheColorFilter: cacheColorFilter,
201190
);
@@ -266,7 +255,6 @@ class RiveGenImage {
266255
Alignment? alignment,
267256
Widget? placeHolder,
268257
bool antialiasing = true,
269-
bool useArtboardSize = false,
270258
List<RiveAnimationController> controllers = const [],
271259
OnInitCallback? onInit,
272260
}) {
@@ -279,7 +267,6 @@ class RiveGenImage {
279267
alignment: alignment,
280268
placeHolder: placeHolder,
281269
antialiasing: antialiasing,
282-
useArtboardSize: useArtboardSize,
283270
controllers: controllers,
284271
onInit: onInit,
285272
);

packages/core/lib/generators/integrations/svg_integration.dart

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,21 @@ class SvgIntegration extends Integration {
2222
String get classOutput => _classDefinition;
2323

2424
String get _classDefinition => '''class SvgGenImage {
25-
const SvgGenImage(this._assetName, {this.size = null, this.isVecFormat = false});
26-
const SvgGenImage.vec(this._assetName, {this.size = null, this.isVecFormat = true});
25+
const SvgGenImage(
26+
this._assetName, {
27+
this.size = null,
28+
}) : this._isVecFormat = false;
29+
30+
const SvgGenImage.vec(
31+
this._assetName, {
32+
this.size = null,
33+
}) : this._isVecFormat = true;
2734
2835
final String _assetName;
2936
${isPackage ? "\n static const String package = '$packageName';" : ''}
3037
3138
final Size? size;
32-
final bool isVecFormat;
39+
final bool _isVecFormat;
3340
3441
SvgPicture svg({
3542
Key? key,
@@ -53,10 +60,9 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''}
5360
@deprecated bool cacheColorFilter = false,
5461
}) {
5562
return SvgPicture(
56-
switch (isVecFormat) {
57-
true => AssetBytesLoader(_assetName, assetBundle: bundle, packageName: package),
58-
false => SvgAssetLoader(_assetName, assetBundle: bundle, packageName: package),
59-
},
63+
_isVecFormat ?
64+
AssetBytesLoader(_assetName, assetBundle: bundle, packageName: package) :
65+
SvgAssetLoader(_assetName, assetBundle: bundle, packageName: package),
6066
key: key,
6167
matchTextDirection: matchTextDirection,
6268
width: width,
@@ -87,11 +93,11 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''}
8793
// Query extra information about the SVG
8894
ImageMetadata? info = parseMetadata ? _getMetadata(asset) : null;
8995

90-
String funcName =
96+
final String constructorName =
9197
asset.extension == '.vec' ? 'SvgGenImage.vec' : 'SvgGenImage';
9298

93-
return '$funcName(\'${asset.posixStylePath}\''
94-
'${(info != null) ? ', size: Size(${info.width}, ${info.height})' : ''}'
99+
return "$constructorName('${asset.posixStylePath}'"
100+
"${(info != null) ? ', size: Size(${info.width}, ${info.height})' : ''}"
95101
')';
96102
}
97103

@@ -113,7 +119,7 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''}
113119

114120
@override
115121
bool isSupport(AssetType asset) =>
116-
(asset.mime == 'image/svg+xml' || asset.extension == '.vec');
122+
asset.mime == 'image/svg+xml' || asset.extension == '.vec';
117123

118124
@override
119125
bool get isConstConstructor => true;

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

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

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

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

0 commit comments

Comments
 (0)