// ignore_for_file: avoid_print import 'package:spine_flutter/spine_flutter.dart'; import 'package:flutter/material.dart'; class AnimationStateEvents extends StatelessWidget { const AnimationStateEvents({super.key}); @override Widget build(BuildContext context) { reportLeaks(); final controller = SpineWidgetController( onInitialized: (controller) { controller.skeleton.scaleX = 0.5; controller.skeleton.scaleY = 0.5; controller.skeleton.findSlot("gun")?.pose.color.set(1, 0, 0, 1); controller.animationStateData.defaultMix = 0.2; controller.animationState.setAnimation(0, "walk", true).setListener((type, trackEntry, event) { print("Walk animation event $type"); }); controller.animationState.addAnimation(0, "jump", false, 2); controller.animationState.addAnimation(0, "run", true, 0).setListener((type, trackEntry, event) { print("Run animation event $type"); }); controller.animationState.setListener((type, trackEntry, event) { if (type == EventType.event) { print( "User event: { name: ${event?.data.name}, intValue: ${event?.intValue}, floatValue: ${event?.floatValue}, stringValue: ${event?.stringValue} }", ); } }); print("Current: ${controller.animationState.getCurrent(0)?.animation.name}"); }, ); return Scaffold( appBar: AppBar(title: const Text('Animation State Listener')), body: Column( children: [ const Text("See output in console!"), Expanded(child: SpineWidget.fromAsset("assets/spineboy.atlas", "assets/spineboy-pro.skel", controller)), ], ), ); } }