Adds artboard parameter to onInit callback

This commit is contained in:
matt Sullivan
2021-06-18 11:02:53 -07:00
parent e589a121d6
commit 794bb90147
9 changed files with 67 additions and 8 deletions

View File

@ -1,3 +1,6 @@
## [0.7.19] - 2021-06-18 12:00:00
- BREAKING CHANGE: onInit callback now takes an artboard as a parameter
- Adds simple state machine example
## [0.7.18] - 2021-06-14 12:00:00
- Adds ability to pass controllers into RiveAnimation widgets
- Adds autoplay option to SimpleAnimation controller

View File

@ -8,7 +8,7 @@ Runtime docs are available in [Rive's help center](https://help.rive.app/runtime
```yaml
dependencies:
rive: ^0.7.18
rive: ^0.7.19
```
## Quick Start

View File

@ -6,6 +6,7 @@ import 'package:rive_example/example_state_machine.dart';
import 'package:rive_example/liquid_download.dart';
import 'package:rive_example/little_machine.dart';
import 'package:rive_example/simple_animation.dart';
import 'package:rive_example/simple_state_machine.dart';
import 'package:rive_example/state_machine_skills.dart';
void main() => runApp(MaterialApp(
@ -133,6 +134,20 @@ class Home extends StatelessWidget {
);
},
),
const SizedBox(
height: 10,
),
ElevatedButton(
child: const Text('Simple State Machine'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (context) => const SimpleStateMachine(),
),
);
},
),
],
),
),

View File

@ -38,7 +38,7 @@ class _PlayPauseAnimationState extends State<PlayPauseAnimation> {
'https://cdn.rive.app/animations/vehicles.riv',
controllers: [_controller],
// Update the play state when the widget's initialized
onInit: () => setState(() {}),
onInit: (_) => setState(() {}),
),
),
floatingActionButton: FloatingActionButton(

View File

@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
class SimpleStateMachine extends StatefulWidget {
const SimpleStateMachine({Key? key}) : super(key: key);
@override
_SimpleStateMachineState createState() => _SimpleStateMachineState();
}
class _SimpleStateMachineState extends State<SimpleStateMachine> {
SMITrigger? _bump;
void _onRiveInit(Artboard artboard) {
final controller = StateMachineController.fromArtboard(artboard, 'bumpy');
artboard.addController(controller!);
_bump = controller.findInput<bool>('bump') as SMITrigger;
}
void _hitBump() => _bump?.fire();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Simple Animation'),
),
body: Center(
child: GestureDetector(
child: RiveAnimation.network(
'https://cdn.rive.app/animations/vehicles.riv',
fit: BoxFit.cover,
onInit: _onRiveInit,
),
onTap: _hitBump,
),
),
);
}
}

View File

@ -21,5 +21,5 @@ export 'package:rive/src/rive_core/shapes/paint/stroke.dart';
export 'package:rive/src/rive_core/shapes/shape.dart';
export 'package:rive/src/rive_file.dart';
export 'package:rive/src/runtime_artboard.dart';
export 'package:rive/src/state_machine_controller.dart';
export 'package:rive/src/controllers/state_machine_controller.dart';
export 'package:rive/src/widgets/rive_animation.dart';

View File

@ -1,5 +1,3 @@
import 'dart:ui' show VoidCallback;
import 'package:flutter/widgets.dart';
import 'package:rive/rive.dart';
import 'package:rive/src/rive_core/artboard.dart';
@ -10,6 +8,9 @@ enum _Source {
network,
}
/// The callback signature for onInit
typedef OnInitCallback = void Function(Artboard);
/// High level widget that plays an animation from a Rive file. If artboard or
/// animation are not specified, the default artboard and first animation fonund
/// within it are used.
@ -46,7 +47,7 @@ class RiveAnimation extends StatefulWidget {
final List<RiveAnimationController> controllers;
/// Callback fired when Riveanimation has initialized
final VoidCallback? onInit;
final OnInitCallback? onInit;
/// Creates a new RiveAnimation from an asset bundle
const RiveAnimation.asset(
@ -137,7 +138,7 @@ class _RiveAnimationState extends State<RiveAnimation> {
setState(() => _artboard = artboard);
// Call the onInit callback if provided
widget.onInit?.call();
widget.onInit?.call(_artboard!);
}
@override

View File

@ -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.7.18
version: 0.7.19
repository: https://github.com/rive-app/rive-flutter
homepage: https://rive.app