Files
rive-flutter/example/lib/simple_state_machine.dart
HayesGordon 4e2547d08d Expose methods to easily get Rive state machine inputs
Our current API is quite verbose and requires casting to the relevant class types when using the current find API. These methods simplify the process.

Diffs=
1460f5366 Expose methods to easily get Rive state machine inputs (#7085)

Co-authored-by: Gordon <pggordonhayes@gmail.com>
2024-04-22 10:11:46 +00:00

58 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
/// An example demonstrating a simple state machine.
///
/// The "bumpy" state machine will be activated on tap of the vehicle.
class SimpleStateMachine extends StatefulWidget {
const SimpleStateMachine({Key? key}) : super(key: key);
@override
State<SimpleStateMachine> createState() => _SimpleStateMachineState();
}
class _SimpleStateMachineState extends State<SimpleStateMachine> {
SMITrigger? _bump;
void _onRiveInit(Artboard artboard) {
final controller = StateMachineController.fromArtboard(artboard, 'bumpy');
artboard.addController(controller!);
_bump = controller.getTriggerInput('bump');
}
void _hitBump() => _bump?.fire();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Simple State Machine'),
),
body: Stack(
children: [
Center(
child: GestureDetector(
onTap: _hitBump,
child: RiveAnimation.asset(
'assets/vehicles.riv',
fit: BoxFit.cover,
onInit: _onRiveInit,
),
),
),
const Align(
alignment: Alignment.topCenter,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Text(
'Bump the van!',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
),
],
),
);
}
}