Repository: rrousselGit/flutter_hooks (dart)

Issue:
useAnimationController doesn't use reverseDuration
Currently useAnimationController doesn't accept reverseDuration as a parameter to pass to the AnimationController it creates. 

I just made a fork to add this for myself, and I'm happy to make a pull request - I just wanted to make sure this wasn't left out for a reason.

Pull request description:
resolves #247

Patch:
diff --git a/packages/flutter_hooks/lib/src/animation.dart b/packages/flutter_hooks/lib/src/animation.dart
index dcb50718..32ad92d1 100644
--- a/packages/flutter_hooks/lib/src/animation.dart
+++ b/packages/flutter_hooks/lib/src/animation.dart
@@ -42,6 +42,7 @@ class _UseAnimationStateHook extends _ListenableStateHook {
 ///   * [useAnimation], to listen to the created [AnimationController].
 AnimationController useAnimationController({
   Duration? duration,
+  Duration? reverseDuration,
   String? debugLabel,
   double initialValue = 0,
   double lowerBound = 0,
@@ -55,6 +56,7 @@ AnimationController useAnimationController({
   return use(
     _AnimationControllerHook(
       duration: duration,
+      reverseDuration: reverseDuration,
       debugLabel: debugLabel,
       initialValue: initialValue,
       lowerBound: lowerBound,
@@ -69,6 +71,7 @@ AnimationController useAnimationController({
 class _AnimationControllerHook extends Hook<AnimationController> {
   const _AnimationControllerHook({
     this.duration,
+    this.reverseDuration,
     this.debugLabel,
     required this.initialValue,
     required this.lowerBound,
@@ -79,6 +82,7 @@ class _AnimationControllerHook extends Hook<AnimationController> {
   }) : super(keys: keys);
 
   final Duration? duration;
+  final Duration? reverseDuration;
   final String? debugLabel;
   final double initialValue;
   final double lowerBound;
@@ -94,6 +98,7 @@ class _AnimationControllerHook extends Hook<AnimationController> {
   void debugFillProperties(DiagnosticPropertiesBuilder properties) {
     super.debugFillProperties(properties);
     properties.add(DiagnosticsProperty('duration', duration));
+    properties.add(DiagnosticsProperty('reverseDuration', reverseDuration));
   }
 }
 
@@ -102,6 +107,7 @@ class _AnimationControllerHookState
   late final AnimationController _animationController = AnimationController(
     vsync: hook.vsync,
     duration: hook.duration,
+    reverseDuration: hook.reverseDuration,
     debugLabel: hook.debugLabel,
     lowerBound: hook.lowerBound,
     upperBound: hook.upperBound,
@@ -119,6 +125,10 @@ class _AnimationControllerHookState
     if (hook.duration != oldHook.duration) {
       _animationController.duration = hook.duration;
     }
+
+    if (hook.reverseDuration != oldHook.reverseDuration) {
+      _animationController.reverseDuration = hook.reverseDuration;
+    }
   }
 
   @override


Test patch:
diff --git a/packages/flutter_hooks/test/use_animation_controller_test.dart b/packages/flutter_hooks/test/use_animation_controller_test.dart
index d424a941..bf766aae 100644
--- a/packages/flutter_hooks/test/use_animation_controller_test.dart
+++ b/packages/flutter_hooks/test/use_animation_controller_test.dart
@@ -17,6 +17,7 @@ void main() {
     );
 
     expect(controller.duration, isNull);
+    expect(controller.reverseDuration, isNull);
     expect(controller.lowerBound, 0);
     expect(controller.upperBound, 1);
     expect(controller.value, 0);
@@ -25,6 +26,7 @@ void main() {
 
     controller
       ..duration = const Duration(seconds: 1)
+      ..reverseDuration = const Duration(seconds: 1)
       // check has a ticker
       ..forward();
 
@@ -38,6 +40,7 @@ void main() {
         useAnimationController(
           animationBehavior: AnimationBehavior.preserve,
           duration: const Duration(seconds: 1),
+          reverseDuration: const Duration(milliseconds: 500),
           initialValue: 42,
           lowerBound: 24,
           upperBound: 84,
@@ -58,7 +61,8 @@ void main() {
         ' │ useSingleTickerProvider\n'
         ' │ useAnimationController:\n'
         ' │   _AnimationControllerHookState#00000(AnimationController#00000(▶\n'
-        ' │   42.000; paused; for Foo), duration: 0:00:01.000000)\n'
+        ' │   42.000; paused; for Foo), duration: 0:00:01.000000,\n'
+        ' │   reverseDuration: 0:00:00.500000)\n'
         ' └SizedBox(renderObject: RenderConstrainedBox#00000)\n',
       ),
     );
@@ -80,6 +84,7 @@ void main() {
           vsync: provider,
           animationBehavior: AnimationBehavior.preserve,
           duration: const Duration(seconds: 1),
+          reverseDuration: const Duration(milliseconds: 500),
           initialValue: 42,
           lowerBound: 24,
           upperBound: 84,
@@ -96,6 +101,7 @@ void main() {
     // ignore: unawaited_futures
     controller.forward();
     expect(controller.duration, const Duration(seconds: 1));
+    expect(controller.reverseDuration, const Duration(milliseconds: 500));
     expect(controller.lowerBound, 24);
     expect(controller.upperBound, 84);
     expect(controller.value, 42);
@@ -113,6 +119,7 @@ void main() {
         controller = useAnimationController(
           vsync: provider,
           duration: const Duration(seconds: 2),
+          reverseDuration: const Duration(seconds: 1),
           debugLabel: 'Bar',
         );
         return Container();
@@ -123,6 +130,7 @@ void main() {
     verifyNoMoreInteractions(provider);
     expect(controller, previousController);
     expect(controller.duration, const Duration(seconds: 2));
+    expect(controller.reverseDuration, const Duration(seconds: 1));
     expect(controller.lowerBound, 24);
     expect(controller.upperBound, 84);
     expect(controller.value, 42);