Skip to content

Commit d40ce2a

Browse files
authored
Merge pull request #26 from eugenekan-dev/feature/custom_animation_controller_support
Feature/custom animation controller support
2 parents 3d02980 + 5d26583 commit d40ce2a

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

lib/src/widget.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AdvancedDrawer extends StatefulWidget {
1515
this.animateChildDecoration = true,
1616
this.rtlOpening = false,
1717
this.disabledGestures = false,
18+
this.animationController,
1819
}) : super(key: key);
1920

2021
/// Child widget. (Usually widget that represent a screen)
@@ -51,6 +52,9 @@ class AdvancedDrawer extends StatefulWidget {
5152
/// Disable gestures.
5253
final bool disabledGestures;
5354

55+
/// Controller that controlls widget animation.
56+
final AnimationController? animationController;
57+
5458
@override
5559
_AdvancedDrawerState createState() => _AdvancedDrawerState();
5660
}
@@ -75,11 +79,13 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
7579
_controller = widget.controller ?? AdvancedDrawerController();
7680
_controller.addListener(handleControllerChanged);
7781

78-
_animationController = AnimationController(
79-
vsync: this,
80-
duration: widget.animationDuration,
81-
value: _controller.value.visible ? 1 : 0,
82-
);
82+
_animationController = widget.animationController ??
83+
AnimationController(
84+
vsync: this,
85+
value: _controller.value.visible ? 1 : 0,
86+
);
87+
88+
_animationController.duration = widget.animationDuration;
8389

8490
final parentAnimation = widget.animationCurve != null
8591
? CurvedAnimation(
@@ -259,12 +265,15 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
259265
@override
260266
void dispose() {
261267
_controller.removeListener(handleControllerChanged);
262-
_animationController.dispose();
263268

264269
if (widget.controller == null) {
265270
_controller.dispose();
266271
}
267272

273+
if (widget.animationContoller == null) {
274+
_animationController.dispose();
275+
}
276+
268277
super.dispose();
269278
}
270279
}

0 commit comments

Comments
 (0)