diff --git a/lib/src/helper/utils.dart b/lib/src/helper/utils.dart index f8f870d..58a264e 100644 --- a/lib/src/helper/utils.dart +++ b/lib/src/helper/utils.dart @@ -2,6 +2,10 @@ import 'dart:ui'; import 'package:flutter_slider_drawer/flutter_slider_drawer.dart'; +/// Signature for the callback that's called when a [DrawerController] is +/// opened or closed. +typedef DrawerCallback = void Function(bool isOpened); + class Utils { /// /// This method get Offset base on [sliderOpen] type diff --git a/lib/src/slider.dart b/lib/src/slider.dart index 1ac125c..d72c180 100644 --- a/lib/src/slider.dart +++ b/lib/src/slider.dart @@ -92,20 +92,24 @@ class SliderDrawer extends StatefulWidget { /// final bool isCupertino; - const SliderDrawer( - {Key? key, - required this.slider, - required this.child, - this.isDraggable = true, - this.animationDuration = 400, - this.sliderOpenSize = 265, - this.splashColor = const Color(0xffffff), - this.sliderCloseSize = 0, - this.slideDirection = SlideDirection.LEFT_TO_RIGHT, - this.sliderBoxShadow, - this.appBar = const SliderAppBar(), - this.isCupertino = false}) - : super(key: key); + /// Optional callback that is called when the [Scaffold.drawer] is opened or closed. + final DrawerCallback? onDrawerChanged; + + const SliderDrawer({ + Key? key, + required this.slider, + required this.child, + this.isDraggable = true, + this.animationDuration = 400, + this.sliderOpenSize = 265, + this.splashColor = const Color(0xffffff), + this.sliderCloseSize = 0, + this.slideDirection = SlideDirection.LEFT_TO_RIGHT, + this.sliderBoxShadow, + this.appBar = const SliderAppBar(), + this.isCupertino = false, + this.onDrawerChanged, + }) : super(key: key); @override SliderDrawerState createState() => SliderDrawerState(); @@ -146,8 +150,14 @@ class SliderDrawerState extends State super.initState(); _animationDrawerController = AnimationController( - vsync: this, - duration: Duration(milliseconds: widget.animationDuration)); + vsync: this, duration: Duration(milliseconds: widget.animationDuration)) + ..addStatusListener((status) { + if (status == AnimationStatus.completed) { + widget.onDrawerChanged?.call(true); + } else if (status == AnimationStatus.dismissed) { + widget.onDrawerChanged?.call(false); + } + }); _animation = Tween(begin: widget.sliderCloseSize, end: widget.sliderOpenSize)