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 createState() => _SimpleStateMachineState(); } class _SimpleStateMachineState extends State { SMITrigger? _bump; void _onRiveInit(Artboard artboard) { final controller = StateMachineController.fromArtboard(artboard, 'bumpy'); artboard.addController(controller!); _bump = controller.findInput('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), ), ), ), ], ), ); } }