mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-07-28 10:52:47 +08:00
Adds artboard parameter to onInit callback
This commit is contained in:
@ -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
|
## [0.7.18] - 2021-06-14 12:00:00
|
||||||
- Adds ability to pass controllers into RiveAnimation widgets
|
- Adds ability to pass controllers into RiveAnimation widgets
|
||||||
- Adds autoplay option to SimpleAnimation controller
|
- Adds autoplay option to SimpleAnimation controller
|
||||||
|
@ -8,7 +8,7 @@ Runtime docs are available in [Rive's help center](https://help.rive.app/runtime
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
dependencies:
|
dependencies:
|
||||||
rive: ^0.7.18
|
rive: ^0.7.19
|
||||||
```
|
```
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
@ -6,6 +6,7 @@ import 'package:rive_example/example_state_machine.dart';
|
|||||||
import 'package:rive_example/liquid_download.dart';
|
import 'package:rive_example/liquid_download.dart';
|
||||||
import 'package:rive_example/little_machine.dart';
|
import 'package:rive_example/little_machine.dart';
|
||||||
import 'package:rive_example/simple_animation.dart';
|
import 'package:rive_example/simple_animation.dart';
|
||||||
|
import 'package:rive_example/simple_state_machine.dart';
|
||||||
import 'package:rive_example/state_machine_skills.dart';
|
import 'package:rive_example/state_machine_skills.dart';
|
||||||
|
|
||||||
void main() => runApp(MaterialApp(
|
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(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -38,7 +38,7 @@ class _PlayPauseAnimationState extends State<PlayPauseAnimation> {
|
|||||||
'https://cdn.rive.app/animations/vehicles.riv',
|
'https://cdn.rive.app/animations/vehicles.riv',
|
||||||
controllers: [_controller],
|
controllers: [_controller],
|
||||||
// Update the play state when the widget's initialized
|
// Update the play state when the widget's initialized
|
||||||
onInit: () => setState(() {}),
|
onInit: (_) => setState(() {}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
|
40
example/lib/simple_state_machine.dart
Normal file
40
example/lib/simple_state_machine.dart
Normal 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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -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_core/shapes/shape.dart';
|
||||||
export 'package:rive/src/rive_file.dart';
|
export 'package:rive/src/rive_file.dart';
|
||||||
export 'package:rive/src/runtime_artboard.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';
|
export 'package:rive/src/widgets/rive_animation.dart';
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import 'dart:ui' show VoidCallback;
|
|
||||||
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:rive/rive.dart';
|
import 'package:rive/rive.dart';
|
||||||
import 'package:rive/src/rive_core/artboard.dart';
|
import 'package:rive/src/rive_core/artboard.dart';
|
||||||
@ -10,6 +8,9 @@ enum _Source {
|
|||||||
network,
|
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
|
/// 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
|
/// animation are not specified, the default artboard and first animation fonund
|
||||||
/// within it are used.
|
/// within it are used.
|
||||||
@ -46,7 +47,7 @@ class RiveAnimation extends StatefulWidget {
|
|||||||
final List<RiveAnimationController> controllers;
|
final List<RiveAnimationController> controllers;
|
||||||
|
|
||||||
/// Callback fired when Riveanimation has initialized
|
/// Callback fired when Riveanimation has initialized
|
||||||
final VoidCallback? onInit;
|
final OnInitCallback? onInit;
|
||||||
|
|
||||||
/// Creates a new RiveAnimation from an asset bundle
|
/// Creates a new RiveAnimation from an asset bundle
|
||||||
const RiveAnimation.asset(
|
const RiveAnimation.asset(
|
||||||
@ -137,7 +138,7 @@ class _RiveAnimationState extends State<RiveAnimation> {
|
|||||||
setState(() => _artboard = artboard);
|
setState(() => _artboard = artboard);
|
||||||
|
|
||||||
// Call the onInit callback if provided
|
// Call the onInit callback if provided
|
||||||
widget.onInit?.call();
|
widget.onInit?.call(_artboard!);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: rive
|
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.
|
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
|
repository: https://github.com/rive-app/rive-flutter
|
||||||
homepage: https://rive.app
|
homepage: https://rive.app
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user