Closed Joker9090 closed 3 years ago
Hi! We currently only expose lower level access to the api in order to figure out what our high level api will look like.
That means it's a little bit verbose to figure this out right now. One way is to write your own controller, inspired from our SimpleController example. When the animation advance returns false, it has completed (if it's not looping): https://github.com/rive-app/rive-flutter/blob/39eddb4fd627d51348dedea112cec9d8c8ff90f4/lib/src/controllers/simple_controller.dart#L34
You can write your own controller that is called back as time changes. You can use that to manually advance and track time and apply/mix animations as you need. Let me know if that helps or if you'd like a specific example...
Great!! For now, I can use this flag for what I need. But it will be awesome if there will be a listener with de progress percentage!
My code for now
_animationController1.isActiveChanged.addListener(() { if (_animationController1.isActive == false) { _playAnimation2(); } });
Thx for all!
That totally works! We're trying to figure out if we want to supply such example cases as complementary example controllers that end users can use with their projects or if we need to provide some kind of higher-level controller in the main library itself. We're still deciding, please let us know if you have any thoughts.
@Joker9090 your code helped a lot, thx for that. I am wondering if you know a way to call setState in the listener.
I want to add flutter overlay over my animation once it is finished, but when I call setState within the listener I get the error, that another rebuild can't be scheduled. This hints that the widget rebuild is still active, even though the animation is marked finished.
Hi @noobloser. Glad to help! In my case, I dont need to fire setState inside de listener, but there should be no error on calling setState inside the listener. Can you please provide the full Code? and also the errro!
Here is my fullCode for 3 animations chained
```dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rive/rive.dart';
class CommonAnimation2 extends StatefulWidget {
const CommonAnimation2({Key key}) : super(key: key);
@override
_CommonAnimation2State createState() => _CommonAnimation2State();
}
class _CommonAnimation2State extends State
@Joker9090 wow, thank you for your quick answer :D I found the solution myself, as it had nothing to do with rive. But I am sure, your full code example will help others too, bc of the limited docu for rive2 :/
anyway, I solved it by wrapping my setState in a scheduler
animationOpen.isActiveChanged.addListener(() {
if (animationOpen.isActive == false) {
SchedulerBinding.instance.addPostFrameCallback((_) {
setState(() => isOpen = true);
});
}
});
Hello! I Can't figured out how to detect the progress percentage of the animations. Is there any why to detect whe animation finish? Thx!