Files
rive-flutter/example/lib/skinning_demo.dart
HayesGordon 00798ca173 Perf/flutter runtime opacity check
- Adds checks to see if a drawable has a 0% opacity before performing draw commands
- Add skinning example

Diffs=
a61f4c6b5 apply changes to rive_core
8152b8a02 docs: update CHANGELOG
b8f61022c perf: check if opacity is 0 before drawing
4c4826e67 chore: add typedef argument names
ff94982f9 docs: add skinning sample
f1ddd88d4 Fix artboard pieces slowly popping in. (#4818)
3039909c2 Update to using deployment workflow similar to ios
53a8f9517 Fix direction when looping. (#4786)
4c5a576ad Fix ping pong hang (#4776)
ae1e02afc Fix tess test linking (#4773)
4ecbf9321 Fix remap based on issue JC caught. (#4771)
89e38b700 allow negative speed (#4770)
4d115b4c6 Adding GLSL100 for tess renderer. (#4767)
31a3972aa ios shaders for tess (#4765)
686e5125b Add dependency to correct grand parent for linear gradients. (#4753)
e737ee427 Revert "Update to using deployment workflow similar to ios"
de0e57d55 Update to using deployment workflow similar to ios
051769242 Runtime Text! (#4741)
331ad0d55 Build cleanups
2538229d6 Use Rive's libpng premake dependency in golden testing
42a0377bc Fix condition with trim paths where all contours are 0 length. (#4722)
ea1c83d02 Use os.copyfile() instead of the '{COPY}' command
5c03e1640 Remove forcing arch to arm64 for libpng (#4715)
404a04d35 Cleaning up libpng premake to be isolated/stand-alone. (#4713)
2023-02-13 18:13:08 +00:00

107 lines
2.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
/// Basic skinning example. The skinning states is set in the Rive editor and
/// triggers are used to change the value.
class SkinningDemo extends StatefulWidget {
const SkinningDemo({Key? key}) : super(key: key);
@override
State<SkinningDemo> createState() => _SkinningDemoState();
}
class _SkinningDemoState extends State<SkinningDemo> {
static const _skinMapping = {
"Skin_0": "Plain",
"Skin_1": "Summer",
"Skin_2": "Elvis",
"Skin_3": "Superhero",
"Skin_4": "Astronaut"
};
String _currentState = 'Plain';
SMITrigger? _skin;
void _onRiveInit(Artboard artboard) {
final controller = StateMachineController.fromArtboard(
artboard,
'Motion',
onStateChange: _onStateChange,
);
artboard.addController(controller!);
_skin = controller.findInput<bool>('Skin') as SMITrigger;
}
void _onStateChange(String stateMachineName, String stateName) {
if (stateName.contains("Skin_")) {
setState(() {
_currentState = _skinMapping[stateName] ?? 'Plain';
});
}
}
void _swapSkin() {
_skin?.fire();
}
@override
Widget build(BuildContext context) {
const textColor = Color(0xFFefcb7d);
return Scaffold(
appBar: AppBar(
title: const Text('Skinning Demo'),
),
body: Stack(
children: [
Center(
child: RiveAnimation.asset(
'assets/skins_demo.riv',
fit: BoxFit.cover,
onInit: _onRiveInit,
),
),
Align(
alignment: Alignment.topCenter,
child: Column(
children: [
const Padding(
padding: EdgeInsets.all(24.0),
child: Text(
'Choose an Avatar',
style: TextStyle(
fontSize: 48,
fontWeight: FontWeight.bold,
color: textColor,
),
),
),
FilledButton(
onPressed: _swapSkin,
style: const ButtonStyle(
backgroundColor:
MaterialStatePropertyAll(Color(0xFF7d99ef)),
),
child: const Text('Swap Skin'),
),
const Spacer(),
Text(
'Skin: $_currentState',
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: textColor,
),
),
const SizedBox(height: 48)
],
),
)
],
),
);
}
}