
There are a number of questions I'd like to resolve before considering to merge this. also a few thigns to clean up no doubt # Questions before merging To customize loading out of band assets, we expect our users to implement ``` abstract class FileAssetLoader { Future<bool> load(FileAsset asset); bool isCompatible(FileAsset asset) => true; } ``` 1. is this a good interface (i've changed `loadContents`, to `load`)? (if we like this we should change this in cpp too) 2. `FileAssetLoader` is a mouth-full, would `AssetLoader` be better? 3. We are passing `FileAssets` (our core objects) to users with some slight api extensions, is that good? should we just wrap this in an Asset class (I had this before, its not a lot of work to get it back) things sorted - [x] cdn "loading" vs url loading - just sticking with cdn, users can customize for url - [x] asset class for consumers of our runtime. - i've avoided this one for now, just extending our FileAsset - [x] Importer/Resolver/Loader. I flipped some names around, mostly because I want our end users to provide an `AssetLoader`, not a resolver. things to sort out down the line, i'm declaring them out of scope for this pr, fft disagree: - Fallback font, I see we have a fallback font file hardcoded in the runtime. should investigate if we can include an asset for people like this, or if we need to have users set this if they want to use fallback fonts. - Image Placement, we should strip width/height from runtimes on ImageAssets - What do we want to do about asset loading / decoding errors - TextStyle has both assetId & fontAssetId it gets assetId from the file asset referencer, its nbd, Diffs= 06e959ad2 Font dart runtime (#5411) Co-authored-by: Maxwell Talbot <talbot.maxwell@gmail.com>
Rive Flutter
Rive Flutter is a runtime library for Rive, a real-time interactive design and animation tool.
This library allows you to fully control Rive files with a high-level API for simple interactions and animations, as well as a low-level API for creating custom render loops for multiple artboards, animations, and state machines in a single canvas.
Table of contents
- ⭐ Rive Overview
- 🚀 Getting Started & API docs
- 🔍 Supported Platforms
- 📚 Examples
- 👨💻 Contributing
- ❓ Issues
Overview of Rive
Rive is a powerful tool that helps teams create and run interactive animations for apps, games, and websites. Designers and developers can use the collaborative editor to create motion graphics that respond to different states and user inputs, and then use the lightweight open-source runtime libraries, like Rive Flutter, to load their animations into their projects.
For more information, check out the following resources:
🏡 Homepage
Getting Started
To get started with Rive Flutter, check out the following resources:
For additional help, see the Runtime sections of the Rive help documentation, such as:
Supported Platforms
Be sure to read the platform specific considerations for the Rive Flutter package.
Examples
To see some examples of what you can do with Rive Flutter, check out the following projects:
Here is an example of how to play an animation from a Rive file retrieved over HTTP:
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
void main() {
runApp(MaterialApp(home: SimpleAnimation()));
}
class SimpleAnimation extends StatelessWidget {
const SimpleAnimation({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: RiveAnimation.network(
'https://cdn.rive.app/animations/vehicles.riv',
),
),
);
}
}
To play an animation from an asset bundle, use:
RiveAnimation.asset('assets/truck.riv');
Control playing and pausing a looping animation:
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
void main() {
runApp(MaterialApp(home: PlayPauseAnimation()));
}
class PlayPauseAnimation extends StatefulWidget {
const PlayPauseAnimation({Key? key}) : super(key: key);
@override
_PlayPauseAnimationState createState() => _PlayPauseAnimationState();
}
class _PlayPauseAnimationState extends State<PlayPauseAnimation> {
// Controller for playback
late RiveAnimationController _controller;
// Toggles between play and pause animation states
void _togglePlay() =>
setState(() => _controller.isActive = !_controller.isActive);
/// Tracks if the animation is playing by whether controller is running
bool get isPlaying => _controller.isActive;
@override
void initState() {
super.initState();
_controller = SimpleAnimation('idle');
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RiveAnimation.network(
'https://cdn.rive.app/animations/vehicles.riv',
controllers: [_controller],
// Update the play state when the widget's initialized
onInit: (_) => setState(() {}),
),
),
floatingActionButton: FloatingActionButton(
onPressed: _togglePlay,
tooltip: isPlaying ? 'Pause' : 'Play',
child: Icon(
isPlaying ? Icons.pause : Icons.play_arrow,
),
),
);
}
}
Play a one-shot animation repeatedly on demand
/// Demonstrates playing a one-shot animation on demand
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
void main() {
runApp(MaterialApp(home: PlayOneShotAnimation()));
}
class PlayOneShotAnimation extends StatefulWidget {
const PlayOneShotAnimation({Key? key}) : super(key: key);
@override
_PlayOneShotAnimationState createState() => _PlayOneShotAnimationState();
}
class _PlayOneShotAnimationState extends State<PlayOneShotAnimation> {
/// Controller for playback
late RiveAnimationController _controller;
/// Is the animation currently playing?
bool _isPlaying = false;
@override
void initState() {
super.initState();
_controller = OneShotAnimation(
'bounce',
autoplay: false,
onStop: () => setState(() => _isPlaying = false),
onStart: () => setState(() => _isPlaying = true),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('One-Shot Example'),
),
body: Center(
child: RiveAnimation.network(
'https://cdn.rive.app/animations/vehicles.riv',
animations: const ['idle', 'curves'],
controllers: [_controller],
),
),
floatingActionButton: FloatingActionButton(
// disable the button while playing the animation
onPressed: () => _isPlaying ? null : _controller.isActive = true,
tooltip: 'Play',
child: const Icon(Icons.arrow_upward),
),
);
}
}
Contributing
We love contributions and all are welcome! 💙
Issues
Have an issue with using the runtime, or want to suggest a feature/API to help make your development life better? Log an issue in our issues tab! You can also browse older issues and discussion threads there to see solutions that may have worked for common problems.