Support chaining await calls on controllers (#9389)
With this patch, you can do:
```dart
Future<Null> foo() async {
try {
await controller.forward().orCancel;
await controller.reverse().orCancel;
await controller.forward().orCancel;
} on TickerCanceled {
// did not complete
}
}
```
...in a State's async method, and so long as you dispose of the
controller properly in your dispose, you'll have a nice way of doing
animations in sequence without leaking the controller. try/finally
works as well, if you need to allocate resources and discard them when
canceled.
Simultaneously, you can do:
```dart
Future<Null> foo() async {
await controller.forward().orCancel;
await controller.reverse().orCancel;
await controller.forward().orCancel;
}
```
...and have the same effect, where the method will just silently hang
(and get GC'ed) if the widget is disposed, without leaking anything,
if you don't need to catch the controller being killed.
And all this, without spurious errors for uncaught exceptions on
controllers.
Showing
This diff is collapsed.
Please register or sign in to comment