mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-05-20 14:56:37 +08:00
58 lines
1.5 KiB
Dart
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.findInput<bool>('bump') as SMITrigger;
|
|
}
|
|
|
|
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),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|