diff --git a/README.md b/README.md index d498fa2..df30e01 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ dependencies: - Provide Basic Appbar with customization of color, sizes and title - Dynamic slider open and close offset - Provide drawer icon animation + - Provide RTL and LTR slider open selection # Code diff --git a/lib/src/slider.dart b/lib/src/slider.dart index 9cd789d..4a6502d 100644 --- a/lib/src/slider.dart +++ b/lib/src/slider.dart @@ -63,10 +63,17 @@ class SliderMenuContainerState extends State _isSlideBarOpen ? _animationController.reverse() : _animationController.forward(); - _slideBarXOffset = _isSlideBarOpen - ? widget.sliderMenuCloseOffset - : widget.sliderMenuOpenOffset; - _slideBarYOffset = 0; + if (widget.sliderOpen == SliderOpen.LEFT_TO_RIGHT || + widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT) { + _slideBarXOffset = _isSlideBarOpen + ? widget.sliderMenuCloseOffset + : widget.sliderMenuOpenOffset; + } else { + _slideBarYOffset = _isSlideBarOpen + ? widget.sliderMenuCloseOffset + : widget.sliderMenuOpenOffset; + } + _isSlideBarOpen = !_isSlideBarOpen; }); } @@ -74,7 +81,12 @@ class SliderMenuContainerState extends State void openDrawer() { setState(() { _animationController.forward(); - _slideBarXOffset = widget.sliderMenuOpenOffset; + if (widget.sliderOpen == SliderOpen.LEFT_TO_RIGHT || + widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT) { + _slideBarXOffset = widget.sliderMenuOpenOffset; + } else { + _slideBarYOffset = widget.sliderMenuOpenOffset; + } _isSlideBarOpen = true; }); } @@ -82,8 +94,12 @@ class SliderMenuContainerState extends State void closeDrawer() { setState(() { _animationController.reverse(); - _slideBarXOffset = widget.sliderMenuCloseOffset; - _slideBarYOffset = 0; + if (widget.sliderOpen == SliderOpen.LEFT_TO_RIGHT || + widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT) { + _slideBarXOffset = widget.sliderMenuCloseOffset; + } else { + _slideBarYOffset = widget.sliderMenuCloseOffset; + } _isSlideBarOpen = false; }); } @@ -100,6 +116,7 @@ class SliderMenuContainerState extends State @override Widget build(BuildContext context) { + getTranslationValues(widget.sliderOpen); return Container( child: Stack(children: [ menuWidget(), @@ -110,12 +127,7 @@ class SliderMenuContainerState extends State width: double.infinity, height: double.infinity, color: Colors.white, - transform: Matrix4.translationValues( - widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT - ? -_slideBarXOffset - : _slideBarXOffset, - _slideBarYOffset, - 1.0), + transform: getTranslationValues(widget.sliderOpen), child: Column( children: [ Container( @@ -169,21 +181,53 @@ class SliderMenuContainerState extends State } menuWidget() { - if (widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT) { - return Positioned( - right: 0, - top: 0, - bottom: 0, - child: Container( + switch (widget.sliderOpen) { + case SliderOpen.LEFT_TO_RIGHT: + return Container( width: widget.sliderMenuOpenOffset, child: widget.sliderMenuWidget, - ), - ); - } else { - return Container( - width: widget.sliderMenuOpenOffset, - child: widget.sliderMenuWidget, - ); + ); + break; + case SliderOpen.RIGHT_TO_LEFT: + return Positioned( + right: 0, + top: 0, + bottom: 0, + child: Container( + width: widget.sliderMenuOpenOffset, + child: widget.sliderMenuWidget, + ), + ); + case SliderOpen.TOP_TO_BOTTOM: + return Positioned( + right: 0, + left: 0, + top: 0, + child: Container( + width: widget.sliderMenuOpenOffset, + child: widget.sliderMenuWidget, + ), + ); + break; + } + if (widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT) { + } else {} + } + + Matrix4 getTranslationValues(SliderOpen sliderOpen) { + switch (sliderOpen) { + case SliderOpen.LEFT_TO_RIGHT: + return Matrix4.translationValues( + _slideBarXOffset, _slideBarYOffset, 1.0); + case SliderOpen.RIGHT_TO_LEFT: + return Matrix4.translationValues( + -_slideBarXOffset, _slideBarYOffset, 1.0); + + case SliderOpen.TOP_TO_BOTTOM: + return Matrix4.translationValues(0, _slideBarYOffset, 1.0); + + default: + return Matrix4.translationValues(0, 0, 1.0); } } } diff --git a/lib/src/slider_open.dart b/lib/src/slider_open.dart index 6eab5ce..9fa7f9f 100644 --- a/lib/src/slider_open.dart +++ b/lib/src/slider_open.dart @@ -1 +1 @@ -enum SliderOpen { LEFT_TO_RIGHT, RIGHT_TO_LEFT } +enum SliderOpen { LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM } diff --git a/pubspec.yaml b/pubspec.yaml index 472f220..823527d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,6 @@ name: flutter_slider_drawer -description: A Flutter package with custom implementation of the Sider Drawer Menu -version: 1.0.1 -author: Nikhil Vadoliya +description: A Flutter package with custom implementation of the Slider Drawer Menu +version: 1.0.2 homepage: https://github.com/NikhilVadoliya/Flutter_slider_drawer environment: