Skip to content

Commit ad4f9bc

Browse files
author
Rami AlDhafeeri
committed
update examples
1 parent fc3b740 commit ad4f9bc

File tree

4 files changed

+58
-24
lines changed

4 files changed

+58
-24
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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';
1314
import 'package:flare_flutter/flare_actor.dart';
1415
import 'package:flare_flutter/flare_controller.dart';
1516
import 'package:rive/rive.dart';
@@ -277,11 +278,15 @@ class AssetGenImage {
277278
}
278279

279280
class SvgGenImage {
280-
const SvgGenImage(this._assetName, {this.size = null});
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});
281285

282286
final String _assetName;
283287

284288
final Size? size;
289+
final bool isVecFormat;
285290

286291
SvgPicture svg({
287292
Key? key,
@@ -303,12 +308,15 @@ class SvgGenImage {
303308
@deprecated BlendMode colorBlendMode = BlendMode.srcIn,
304309
@deprecated bool cacheColorFilter = false,
305310
}) {
306-
return SvgPicture.asset(
307-
_assetName,
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+
},
308318
key: key,
309319
matchTextDirection: matchTextDirection,
310-
bundle: bundle,
311-
package: package,
312320
width: width,
313321
height: height,
314322
fit: fit,
@@ -318,9 +326,8 @@ class SvgGenImage {
318326
semanticsLabel: semanticsLabel,
319327
excludeFromSemantics: excludeFromSemantics,
320328
theme: theme,
321-
colorFilter: colorFilter,
322-
color: color,
323-
colorBlendMode: colorBlendMode,
329+
colorFilter: colorFilter ??
330+
(color == null ? null : ColorFilter.mode(color, colorBlendMode)),
324331
clipBehavior: clipBehavior,
325332
cacheColorFilter: cacheColorFilter,
326333
);

examples/example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ description: A sample project using FlutterGen.
33
publish_to: 'none'
44

55
environment:
6-
sdk: '>=2.16.0 <4.0.0'
7-
flutter: '>=3.0.0'
6+
sdk: '>=3.2.0 <4.0.0'
7+
flutter: '>=3.16.0'
88

99
dependencies:
1010
flutter:

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

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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';
1314
import 'package:flare_flutter/flare_actor.dart';
1415
import 'package:flare_flutter/flare_controller.dart';
1516
import 'package:rive/rive.dart';
@@ -55,6 +56,8 @@ class $AssetsUnknownGen {
5556
class ResAssets {
5657
ResAssets._();
5758

59+
static const String package = 'example_resources';
60+
5861
static const $AssetsImagesGen images = $AssetsImagesGen();
5962
static const $AssetsUnknownGen unknown = $AssetsUnknownGen();
6063
}
@@ -64,6 +67,8 @@ class AssetGenImage {
6467

6568
final String _assetName;
6669

70+
static const String package = 'example_resources';
71+
6772
final Size? size;
6873

6974
Image image({
@@ -86,7 +91,8 @@ class AssetGenImage {
8691
bool matchTextDirection = false,
8792
bool gaplessPlayback = false,
8893
bool isAntiAlias = false,
89-
String? package = 'example_resources',
94+
@Deprecated('Do not specify package for a generated library asset')
95+
String? package = package,
9096
FilterQuality filterQuality = FilterQuality.low,
9197
int? cacheWidth,
9298
int? cacheHeight,
@@ -121,7 +127,8 @@ class AssetGenImage {
121127

122128
ImageProvider provider({
123129
AssetBundle? bundle,
124-
String? package = 'example_resources',
130+
@Deprecated('Do not specify package for a generated library asset')
131+
String? package = package,
125132
}) {
126133
return AssetImage(
127134
_assetName,
@@ -136,15 +143,24 @@ class AssetGenImage {
136143
}
137144

138145
class SvgGenImage {
139-
const SvgGenImage(this._assetName);
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});
140150

141151
final String _assetName;
142152

153+
static const String package = 'example_resources';
154+
155+
final Size? size;
156+
final bool isVecFormat;
157+
143158
SvgPicture svg({
144159
Key? key,
145160
bool matchTextDirection = false,
146161
AssetBundle? bundle,
147-
String? package = 'example_resources',
162+
@Deprecated('Do not specify package for a generated library asset')
163+
String? package = package,
148164
double? width,
149165
double? height,
150166
BoxFit fit = BoxFit.contain,
@@ -160,12 +176,15 @@ class SvgGenImage {
160176
@deprecated BlendMode colorBlendMode = BlendMode.srcIn,
161177
@deprecated bool cacheColorFilter = false,
162178
}) {
163-
return SvgPicture.asset(
164-
_assetName,
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+
},
165186
key: key,
166187
matchTextDirection: matchTextDirection,
167-
bundle: bundle,
168-
package: package,
169188
width: width,
170189
height: height,
171190
fit: fit,
@@ -175,9 +194,8 @@ class SvgGenImage {
175194
semanticsLabel: semanticsLabel,
176195
excludeFromSemantics: excludeFromSemantics,
177196
theme: theme,
178-
colorFilter: colorFilter,
179-
color: color,
180-
colorBlendMode: colorBlendMode,
197+
colorFilter: colorFilter ??
198+
(color == null ? null : ColorFilter.mode(color, colorBlendMode)),
181199
clipBehavior: clipBehavior,
182200
cacheColorFilter: cacheColorFilter,
183201
);
@@ -193,6 +211,8 @@ class FlareGenImage {
193211

194212
final String _assetName;
195213

214+
static const String package = 'example_resources';
215+
196216
FlareActor flare({
197217
String? boundsNode,
198218
String? animation,
@@ -236,6 +256,8 @@ class RiveGenImage {
236256

237257
final String _assetName;
238258

259+
static const String package = 'example_resources';
260+
239261
RiveAnimation rive({
240262
String? artboard,
241263
List<String> animations = const [],
@@ -244,6 +266,7 @@ class RiveGenImage {
244266
Alignment? alignment,
245267
Widget? placeHolder,
246268
bool antialiasing = true,
269+
bool useArtboardSize = false,
247270
List<RiveAnimationController> controllers = const [],
248271
OnInitCallback? onInit,
249272
}) {
@@ -256,6 +279,7 @@ class RiveGenImage {
256279
alignment: alignment,
257280
placeHolder: placeHolder,
258281
antialiasing: antialiasing,
282+
useArtboardSize: useArtboardSize,
259283
controllers: controllers,
260284
onInit: onInit,
261285
);
@@ -271,6 +295,8 @@ class LottieGenImage {
271295

272296
final String _assetName;
273297

298+
static const String package = 'example_resources';
299+
274300
LottieBuilder lottie({
275301
Animation<double>? controller,
276302
bool? animate,
@@ -289,7 +315,8 @@ class LottieGenImage {
289315
double? height,
290316
BoxFit? fit,
291317
AlignmentGeometry? alignment,
292-
String? package = 'example_resources',
318+
@Deprecated('Do not specify package for a generated library asset')
319+
String? package = package,
293320
bool? addRepaintBoundary,
294321
FilterQuality? filterQuality,
295322
void Function(String)? onWarning,

examples/example_resources/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ description: A sample project using FlutterGen.
33
publish_to: 'none'
44

55
environment:
6-
sdk: '>=2.16.0 <4.0.0'
7-
flutter: '>=3.0.0'
6+
sdk: '>=3.2.0 <4.0.0'
7+
flutter: '>=3.16.0'
88

99
dependencies:
1010
flutter:

0 commit comments

Comments
 (0)