-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flutter Runtime API for Nested Inputs
https://github.com/rive-app/rive/assets/186340/00b71832-1293-45fa-b3da-f9abcaa34eb7 Diffs= c8a151ebb Flutter Runtime API for Nested Inputs (#7325) e0a786c90 Runtime API for Nested Inputs (#7316) 01d20e026 Use unique_ptr in import stack. (#7307) 5ad13845d Fail early with bad blend modes. (#7302) Co-authored-by: Philip Chung <[email protected]>
- Loading branch information
Showing
8 changed files
with
246 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7474216b457d7d2b29cac2209644f9f3c7821652 | ||
c8a151ebb3a99fe53af068db3da71ced90d21ea2 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:rive/rive.dart'; | ||
|
||
/// An example showing how to drive a StateMachine via one numeric input. | ||
class ArtboardNestedInputs extends StatefulWidget { | ||
const ArtboardNestedInputs({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<ArtboardNestedInputs> createState() => _ArtboardNestedInputsState(); | ||
} | ||
|
||
class _ArtboardNestedInputsState extends State<ArtboardNestedInputs> { | ||
Artboard? _riveArtboard; | ||
SMIBool? _circleOuterState; | ||
SMIBool? _circleInnerState; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
_loadRiveFile(); | ||
} | ||
|
||
Future<void> _loadRiveFile() async { | ||
final file = await RiveFile.asset('assets/runtime_nested_inputs.riv'); | ||
|
||
// The artboard is the root of the animation and gets drawn in the | ||
// Rive widget. | ||
final artboard = file.artboardByName("MainArtboard")!.instance(); | ||
var controller = | ||
StateMachineController.fromArtboard(artboard, 'MainStateMachine'); | ||
// Get the nested input CircleOuterState in the nested artboard CircleOuter | ||
_circleOuterState = | ||
artboard.getBoolInput("CircleOuterState", "CircleOuter"); | ||
// Get the nested input CircleInnerState at the nested artboard path | ||
// -> CircleOuter | ||
// -> CircleInner | ||
_circleInnerState = | ||
artboard.getBoolInput("CircleInnerState", "CircleOuter/CircleInner"); | ||
if (controller != null) { | ||
artboard.addController(controller); | ||
} | ||
setState(() => _riveArtboard = artboard); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Nested Inputs'), | ||
), | ||
body: Center( | ||
child: _riveArtboard == null | ||
? const SizedBox() | ||
: Stack( | ||
children: [ | ||
Positioned.fill( | ||
child: Rive( | ||
artboard: _riveArtboard!, | ||
fit: BoxFit.fitWidth, | ||
), | ||
), | ||
Positioned.fill( | ||
bottom: 32, | ||
child: Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.end, | ||
children: [ | ||
ElevatedButton( | ||
child: const Text('Outer Circle'), | ||
onPressed: () { | ||
if (_circleOuterState != null) { | ||
_circleOuterState!.value = | ||
!_circleOuterState!.value; | ||
} | ||
}, | ||
), | ||
const SizedBox(width: 10), | ||
ElevatedButton( | ||
child: const Text('Inner Circle'), | ||
onPressed: () { | ||
if (_circleInnerState != null) { | ||
_circleInnerState!.value = | ||
!_circleInnerState!.value; | ||
} | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:rive/rive.dart'; | ||
|
||
import 'src/utils.dart'; | ||
|
||
void main() { | ||
late RiveFile riveFile; | ||
|
||
setUp(() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
final riveBytes = loadFile('assets/runtime_nested_inputs.riv'); | ||
riveFile = RiveFile.import(riveBytes); | ||
}); | ||
|
||
test('Nested boolean input can be get/set', () async { | ||
final artboard = riveFile.artboards.first.instance(); | ||
expect(artboard, isNotNull); | ||
final artboardInstance = artboard.instance(); | ||
expect(artboardInstance, isNotNull); | ||
final bool = artboard.getBoolInput("CircleOuterState", "CircleOuter"); | ||
expect(bool, isNotNull); | ||
expect(bool!.value, false); | ||
bool.value = true; | ||
expect(bool.value, true); | ||
}); | ||
|
||
test('Nested number input can be get/set', () async { | ||
final artboard = riveFile.artboards.first.instance(); | ||
expect(artboard, isNotNull); | ||
final artboardInstance = artboard.instance(); | ||
expect(artboardInstance, isNotNull); | ||
final num = artboard.getNumberInput("CircleOuterNumber", "CircleOuter"); | ||
expect(num, isNotNull); | ||
expect(num!.value, 0); | ||
num.value = 99; | ||
expect(num.value, 99); | ||
}); | ||
|
||
test('Nested trigger can be get/fired', () async { | ||
final artboard = riveFile.artboards.first.instance(); | ||
expect(artboard, isNotNull); | ||
final artboardInstance = artboard.instance(); | ||
expect(artboardInstance, isNotNull); | ||
final trigger = | ||
artboard.getTriggerInput("CircleOuterTrigger", "CircleOuter"); | ||
expect(trigger, isNotNull); | ||
trigger!.fire(); | ||
}); | ||
|
||
test('Nested boolean input can be get/set multiple levels deep', () async { | ||
final artboard = riveFile.artboards.first.instance(); | ||
expect(artboard, isNotNull); | ||
final artboardInstance = artboard.instance(); | ||
expect(artboardInstance, isNotNull); | ||
final bool = | ||
artboard.getBoolInput("CircleInnerState", "CircleOuter/CircleInner"); | ||
expect(bool, isNotNull); | ||
expect(bool!.value, false); | ||
bool.value = true; | ||
expect(bool.value, true); | ||
}); | ||
} |