mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-07-18 19:14:20 +08:00
41 lines
1.0 KiB
Dart
41 lines
1.0 KiB
Dart
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,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|