Merging master

This commit is contained in:
Matt Sullivan
2020-11-10 18:55:46 -08:00
6 changed files with 125 additions and 30 deletions

@ -1,3 +1,9 @@
## [0.6.2+1] - 2020-11-?? ??:??:??
- Added default noop implementation to `onActivate`, `onDeactivate`, and `dispose`
in `RiveAnimationController`, which removes the need for noop overrides in subclasses
like `SimpleAnimation`.
## [0.6.2] - 2020-10-02 15:45:10
- Exposed major and minor runtime version (issue #15) via riveVersion.

108
README.md

@ -13,8 +13,112 @@ dependencies:
rive: ^0.6.2
```
## Example
## Examples
See how to use it in [example](example).
### Continuously playing a Looping Animation
Here's a simple example of continuously playing a looping animation.
```dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rive/rive.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _togglePlay() {
setState(() => _controller.isActive = !_controller.isActive);
}
/// Tracks if the animation is playing by whether controller is running.
bool get isPlaying => _controller?.isActive ?? false;
Artboard _riveArtboard;
RiveAnimationController _controller;
@override
void initState() {
super.initState();
// Load the animation file from the bundle, note that you could also
// download this. The RiveFile just expects a list of bytes.
rootBundle.load('assets/off_road_car.riv').then(
(data) async {
final file = RiveFile();
// Load the RiveFile from the binary data.
if (file.import(data)) {
// The artboard is the root of the animation and gets drawn in the
// Rive widget.
final artboard = file.mainArtboard;
// Add a controller to play back a known animation on the main/default
// artboard.We store a reference to it so we can toggle playback.
artboard.addController(_controller = SimpleAnimation('idle'));
setState(() => _riveArtboard = artboard);
}
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: _riveArtboard == null
? const SizedBox()
: Rive(artboard: _riveArtboard),
),
floatingActionButton: FloatingActionButton(
onPressed: _togglePlay,
tooltip: isPlaying ? 'Pause' : 'Play',
child: Icon(
isPlaying ? Icons.pause : Icons.play_arrow,
),
),
);
}
}
```
Check out the full [example](example).
### Playing a one-shot animation
Rive's ```SimpleAnimation``` will automatically play a looping or ping-pong animation repeatedly, but will play a one-shot animation only once. To determine when a one-shot has completed playing, subscribe to the controller's ```isActiveChanged``` listenable:
```dart
// Listen for changes to the controller to know when an animation has
// started or stopped playing
_controller.isActiveChanged.addListener(() {
if (_controller.isActive) {
print('Animation started playing');
} else {
print('Animation stopped playing');
}
}
```
## More Info
For an in-depth tutorial on how to use the runtime, check out [this blog post](https://blog.rive.app/rives-flutter-runtime-part-1/).

@ -2,9 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rive/rive.dart';
void main() {
runApp(MyApp());
}
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
@ -32,8 +30,7 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() => _controller.isActive = !_controller.isActive);
}
/// We track if the animation is playing by whether or not the controller is
/// running.
/// Tracks if the animation is playing by whether controller is running.
bool get isPlaying => _controller?.isActive ?? false;
Artboard _riveArtboard;
@ -46,19 +43,16 @@ class _MyHomePageState extends State<MyHomePage> {
// download this. The RiveFile just expects a list of bytes.
rootBundle.load('assets/off_road_car.riv').then(
(data) async {
var file = RiveFile();
final file = RiveFile();
// Load the RiveFile from the binary data.
var success = file.import(data);
if (success) {
// The artboard is the root of the animation and is what gets drawn
// into the Rive widget.
var artboard = file.mainArtboard;
if (file.import(data)) {
// The artboard is the root of the animation and gets drawn in the
// Rive widget.
final artboard = file.mainArtboard;
// Add a controller to play back a known animation on the main/default
// artboard.We store a reference to it so we can toggle playback.
artboard.addController(
_controller = SimpleAnimation('idle'),
);
artboard.addController(_controller = SimpleAnimation('idle'));
setState(() => _riveArtboard = artboard);
}
},

@ -34,13 +34,4 @@ class SimpleAnimation extends RiveAnimationController<RuntimeArtboard> {
isActive = false;
}
}
@override
void dispose() {}
@override
void onActivate() {}
@override
void onDeactivate() {}
}

@ -17,10 +17,10 @@ abstract class RiveAnimationController<T> {
}
@protected
void onActivate();
void onActivate() {}
@protected
void onDeactivate();
void onDeactivate() {}
void apply(T core, double elapsedSeconds);
bool init(T core) => true;
void dispose();
void dispose() {}
}

@ -1,6 +1,6 @@
name: rive
description: Rive 2 Flutter Runtime. This package provides runtime functionality for playing back and interacting with animations built with the Rive editor available at https://rive.app.
version: 0.6.2
version: 0.6.2+1
repository: https://github.com/rive-app/rive-flutter
homepage: https://rive.app
@ -11,7 +11,7 @@ dependencies:
flutter:
sdk: flutter
graphs: ^0.2.0
meta: ^1.1.8
meta: ^1.2.3
dev_dependencies:
flutter_test: