From f4bc2e1d91ed32b9bcb23eff4ff4696147745d11 Mon Sep 17 00:00:00 2001 From: Fironn Date: Thu, 20 Jun 2024 15:29:00 +0900 Subject: [PATCH 1/2] add onDrawerChanged event handler --- lib/src/helper/utils.dart | 4 ++++ lib/src/slider.dart | 42 ++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 16 deletions(-) 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..8fbdef8 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!(true); + } else if (status == AnimationStatus.dismissed) { + widget.onDrawerChanged!(false); + } + }); _animation = Tween(begin: widget.sliderCloseSize, end: widget.sliderOpenSize) From 06f1ecc52afad50e470ada6fd8619a57fdac8a12 Mon Sep 17 00:00:00 2001 From: Fironn Date: Tue, 18 Mar 2025 12:06:08 +0900 Subject: [PATCH 2/2] use onDrawerChanged?.call(); --- lib/src/slider.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/slider.dart b/lib/src/slider.dart index 8fbdef8..d72c180 100644 --- a/lib/src/slider.dart +++ b/lib/src/slider.dart @@ -153,9 +153,9 @@ class SliderDrawerState extends State vsync: this, duration: Duration(milliseconds: widget.animationDuration)) ..addStatusListener((status) { if (status == AnimationStatus.completed) { - widget.onDrawerChanged!(true); + widget.onDrawerChanged?.call(true); } else if (status == AnimationStatus.dismissed) { - widget.onDrawerChanged!(false); + widget.onDrawerChanged?.call(false); } });