mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-06-27 18:28:18 +08:00
Adds artboard parameter to onInit callback
This commit is contained in:
@ -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(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -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(
|
||||
|
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,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user