Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional package parameter to RiveAnimation.asset constructor #366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/src/widgets/rive_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class RiveAnimation extends StatefulWidget {
/// The asset name or url
final String? name;

/// The package name where the asset is located
final String? package;

/// The Rive File object
final RiveFile? file;

Expand Down Expand Up @@ -85,6 +88,7 @@ class RiveAnimation extends StatefulWidget {
this.fit,
this.alignment,
this.placeHolder,
this.package,
this.antialiasing = true,
this.useArtboardSize = false,
this.clipRect,
Expand Down Expand Up @@ -124,6 +128,7 @@ class RiveAnimation extends StatefulWidget {
Key? key,
}) : name = url,
file = null,
package = null,
src = _Source.network,
super(key: key);

Expand Down Expand Up @@ -152,6 +157,7 @@ class RiveAnimation extends StatefulWidget {
}) : name = path,
file = null,
headers = null,
package = null,
src = _Source.file,
super(key: key);

Expand Down Expand Up @@ -180,6 +186,7 @@ class RiveAnimation extends StatefulWidget {
this.behavior = RiveHitTestBehavior.opaque,
}) : name = null,
headers = null,
package = null,
objectGenerator = null,
src = _Source.direct,
super(key: key);
Expand Down Expand Up @@ -216,8 +223,12 @@ class RiveAnimationState extends State<RiveAnimation> {
Future<RiveFile> _loadRiveFile() {
switch (widget.src) {
case _Source.asset:
String assetLocation = widget.package == null
? widget.name!
: 'packages/${widget.package}/${widget.name!}';

return RiveFile.asset(
widget.name!,
assetLocation,
objectGenerator: widget.objectGenerator,
);
case _Source.network:
Expand All @@ -244,6 +255,7 @@ class RiveAnimationState extends State<RiveAnimation> {

if (widget.name != oldWidget.name ||
widget.file != oldWidget.file ||
widget.package != oldWidget.package ||
widget.src != oldWidget.src) {
_configure(); // Rife file has changed
} else if (_requiresInit(oldWidget)) {
Expand Down