-[Implement][Feature] TopToBottom slide

-Code refactor
master
NikhilVadoliya 5 years ago
parent 1c46340655
commit 3ebccaefdc

@ -27,6 +27,7 @@ dependencies:
- Provide Basic Appbar with customization of color, sizes and title - Provide Basic Appbar with customization of color, sizes and title
- Dynamic slider open and close offset - Dynamic slider open and close offset
- Provide drawer icon animation - Provide drawer icon animation
- Provide RTL and LTR slider open selection
# Code # Code

@ -63,10 +63,17 @@ class SliderMenuContainerState extends State<SliderMenuContainer>
_isSlideBarOpen _isSlideBarOpen
? _animationController.reverse() ? _animationController.reverse()
: _animationController.forward(); : _animationController.forward();
if (widget.sliderOpen == SliderOpen.LEFT_TO_RIGHT ||
widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT) {
_slideBarXOffset = _isSlideBarOpen _slideBarXOffset = _isSlideBarOpen
? widget.sliderMenuCloseOffset ? widget.sliderMenuCloseOffset
: widget.sliderMenuOpenOffset; : widget.sliderMenuOpenOffset;
_slideBarYOffset = 0; } else {
_slideBarYOffset = _isSlideBarOpen
? widget.sliderMenuCloseOffset
: widget.sliderMenuOpenOffset;
}
_isSlideBarOpen = !_isSlideBarOpen; _isSlideBarOpen = !_isSlideBarOpen;
}); });
} }
@ -74,7 +81,12 @@ class SliderMenuContainerState extends State<SliderMenuContainer>
void openDrawer() { void openDrawer() {
setState(() { setState(() {
_animationController.forward(); _animationController.forward();
if (widget.sliderOpen == SliderOpen.LEFT_TO_RIGHT ||
widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT) {
_slideBarXOffset = widget.sliderMenuOpenOffset; _slideBarXOffset = widget.sliderMenuOpenOffset;
} else {
_slideBarYOffset = widget.sliderMenuOpenOffset;
}
_isSlideBarOpen = true; _isSlideBarOpen = true;
}); });
} }
@ -82,8 +94,12 @@ class SliderMenuContainerState extends State<SliderMenuContainer>
void closeDrawer() { void closeDrawer() {
setState(() { setState(() {
_animationController.reverse(); _animationController.reverse();
if (widget.sliderOpen == SliderOpen.LEFT_TO_RIGHT ||
widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT) {
_slideBarXOffset = widget.sliderMenuCloseOffset; _slideBarXOffset = widget.sliderMenuCloseOffset;
_slideBarYOffset = 0; } else {
_slideBarYOffset = widget.sliderMenuCloseOffset;
}
_isSlideBarOpen = false; _isSlideBarOpen = false;
}); });
} }
@ -100,6 +116,7 @@ class SliderMenuContainerState extends State<SliderMenuContainer>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
getTranslationValues(widget.sliderOpen);
return Container( return Container(
child: Stack(children: <Widget>[ child: Stack(children: <Widget>[
menuWidget(), menuWidget(),
@ -110,12 +127,7 @@ class SliderMenuContainerState extends State<SliderMenuContainer>
width: double.infinity, width: double.infinity,
height: double.infinity, height: double.infinity,
color: Colors.white, color: Colors.white,
transform: Matrix4.translationValues( transform: getTranslationValues(widget.sliderOpen),
widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT
? -_slideBarXOffset
: _slideBarXOffset,
_slideBarYOffset,
1.0),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Container( Container(
@ -169,7 +181,14 @@ class SliderMenuContainerState extends State<SliderMenuContainer>
} }
menuWidget() { menuWidget() {
if (widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT) { switch (widget.sliderOpen) {
case SliderOpen.LEFT_TO_RIGHT:
return Container(
width: widget.sliderMenuOpenOffset,
child: widget.sliderMenuWidget,
);
break;
case SliderOpen.RIGHT_TO_LEFT:
return Positioned( return Positioned(
right: 0, right: 0,
top: 0, top: 0,
@ -179,11 +198,36 @@ class SliderMenuContainerState extends State<SliderMenuContainer>
child: widget.sliderMenuWidget, child: widget.sliderMenuWidget,
), ),
); );
} else { case SliderOpen.TOP_TO_BOTTOM:
return Container( return Positioned(
right: 0,
left: 0,
top: 0,
child: Container(
width: widget.sliderMenuOpenOffset, width: widget.sliderMenuOpenOffset,
child: widget.sliderMenuWidget, 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);
} }
} }
} }

@ -1 +1 @@
enum SliderOpen { LEFT_TO_RIGHT, RIGHT_TO_LEFT } enum SliderOpen { LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM }

@ -1,7 +1,6 @@
name: flutter_slider_drawer name: flutter_slider_drawer
description: A Flutter package with custom implementation of the Sider Drawer Menu description: A Flutter package with custom implementation of the Slider Drawer Menu
version: 1.0.1 version: 1.0.2
author: Nikhil Vadoliya <vadoliya.nikhil99@gmail.com>
homepage: https://github.com/NikhilVadoliya/Flutter_slider_drawer homepage: https://github.com/NikhilVadoliya/Flutter_slider_drawer
environment: environment:

Loading…
Cancel
Save