diff --git a/README.md b/README.md index df30e01..09b0ab6 100644 --- a/README.md +++ b/README.md @@ -32,25 +32,30 @@ dependencies: # Code ``` -SliderMenuContainer( + Scaffold( + body: SliderMenuContainer( appBarColor: Colors.white, key: _key, - appBarPadding: const EdgeInsets.only(top: 20), - sliderMenuOpenOffset: 250, + sliderOpen: SliderOpen.TOP_TO_BOTTOM, + appBarPadding: const EdgeInsets.only(top: 10), + sliderMenuOpenOffset: 210, appBarHeight: 60, title: Text( title, style: TextStyle(fontSize: 22, fontWeight: FontWeight.w700), ), - sliderMenuWidget: MenuWidget( + sliderMenu: MenuWidget( + onProfilePictureClick: () {}, onItemClick: (title) { _key.currentState.closeDrawer(); + setState(() { this.title = title; }); }, ), - sliderMainWidget: MainWidget()), + sliderMain: MainWidget()), + ), ``` diff --git a/lib/src/slider.dart b/lib/src/slider.dart index 4a6502d..8317080 100644 --- a/lib/src/slider.dart +++ b/lib/src/slider.dart @@ -2,19 +2,23 @@ import 'package:flutter/material.dart'; import 'package:flutter_slider_drawer/flutter_slider_drawer.dart'; class SliderMenuContainer extends StatefulWidget { - final Widget sliderMenuWidget; - final Widget sliderMainWidget; + final Widget sliderMenu; + final Widget sliderMain; final int sliderAnimationTimeInMilliseconds; final double sliderMenuOpenOffset; final double sliderMenuCloseOffset; - /*final double sliderMainOffset;*/ final Color drawerIconColor; final Widget drawerIcon; final double drawerIconSize; final double appBarHeight; final Widget title; final bool isTitleCenter; + final bool isShadow; + final Color shadowColor; + final double shadowBlurRadius; + final double shadowSpreadRadius; + final Widget trailing; final Color appBarColor; final EdgeInsets appBarPadding; @@ -22,8 +26,8 @@ class SliderMenuContainer extends StatefulWidget { const SliderMenuContainer({ Key key, - this.sliderMenuWidget, - this.sliderMainWidget, + this.sliderMenu, + this.sliderMain, this.sliderAnimationTimeInMilliseconds = 200, this.sliderMenuOpenOffset = 265, this.drawerIconColor = Colors.black, @@ -37,9 +41,12 @@ class SliderMenuContainer extends StatefulWidget { this.appBarHeight, this.sliderMenuCloseOffset = 0, this.sliderOpen = SliderOpen.LEFT_TO_RIGHT, - /* this.sliderMainOffset = 0*/ - }) : assert(sliderMenuWidget != null), - assert(sliderMainWidget != null), + this.isShadow = false, + this.shadowColor = Colors.grey, + this.shadowBlurRadius = 25.0, + this.shadowSpreadRadius = 5.0, + }) : assert(sliderMenu != null), + assert(sliderMain != null), super(key: key); @override @@ -54,10 +61,11 @@ class SliderMenuContainerState extends State AnimationController _animationController; Widget drawerIcon; - double db = 0; + /// check whether drawer is open bool get isDrawerOpen => _isSlideBarOpen; + /// Toggle drawer void toggle() { setState(() { _isSlideBarOpen @@ -78,6 +86,7 @@ class SliderMenuContainerState extends State }); } + /// Open drawer void openDrawer() { setState(() { _animationController.forward(); @@ -91,6 +100,7 @@ class SliderMenuContainerState extends State }); } + /// Close drawer void closeDrawer() { setState(() { _animationController.reverse(); @@ -116,10 +126,35 @@ class SliderMenuContainerState extends State @override Widget build(BuildContext context) { - getTranslationValues(widget.sliderOpen); return Container( child: Stack(children: [ + /// Display Menu menuWidget(), + + /// Displaying the shadow + if (widget.isShadow) ...[ + AnimatedContainer( + duration: + Duration(milliseconds: widget.sliderAnimationTimeInMilliseconds), + curve: Curves.easeIn, + width: double.infinity, + height: double.infinity, + transform: getTranslationValuesForShadow(widget.sliderOpen), + decoration: BoxDecoration(shape: BoxShape.rectangle, boxShadow: [ + BoxShadow( + color: widget.shadowColor, + blurRadius: widget.shadowBlurRadius, // soften the shadow + spreadRadius: widget.shadowSpreadRadius, //extend the shadow + offset: Offset( + 15.0, // Move to right 10 horizontally + 15.0, // Move to bottom 10 Vertically + ), + ) + ]), + ), + ], + + /// Display Main Screen AnimatedContainer( duration: Duration(milliseconds: widget.sliderAnimationTimeInMilliseconds), @@ -137,7 +172,7 @@ class SliderMenuContainerState extends State children: appBar(), ), ), - Expanded(child: widget.sliderMainWidget), + Expanded(child: widget.sliderMain), ], )), ])); @@ -174,18 +209,13 @@ class SliderMenuContainerState extends State return list; } - @override - void dispose() { - super.dispose(); - _animationController.dispose(); - } - + /// Build and Align the Menu widget based on the slide open type menuWidget() { switch (widget.sliderOpen) { case SliderOpen.LEFT_TO_RIGHT: return Container( width: widget.sliderMenuOpenOffset, - child: widget.sliderMenuWidget, + child: widget.sliderMenu, ); break; case SliderOpen.RIGHT_TO_LEFT: @@ -195,7 +225,7 @@ class SliderMenuContainerState extends State bottom: 0, child: Container( width: widget.sliderMenuOpenOffset, - child: widget.sliderMenuWidget, + child: widget.sliderMenu, ), ); case SliderOpen.TOP_TO_BOTTOM: @@ -205,15 +235,17 @@ class SliderMenuContainerState extends State top: 0, child: Container( width: widget.sliderMenuOpenOffset, - child: widget.sliderMenuWidget, + child: widget.sliderMenu, ), ); break; } - if (widget.sliderOpen == SliderOpen.RIGHT_TO_LEFT) { - } else {} } + /// + /// This method get Matrix4 data base on [sliderOpen] type + /// + Matrix4 getTranslationValues(SliderOpen sliderOpen) { switch (sliderOpen) { case SliderOpen.LEFT_TO_RIGHT: @@ -230,4 +262,27 @@ class SliderMenuContainerState extends State return Matrix4.translationValues(0, 0, 1.0); } } + + Matrix4 getTranslationValuesForShadow(SliderOpen sliderOpen) { + switch (sliderOpen) { + case SliderOpen.LEFT_TO_RIGHT: + return Matrix4.translationValues( + _slideBarXOffset - 30, _slideBarYOffset, 1.0); + case SliderOpen.RIGHT_TO_LEFT: + return Matrix4.translationValues( + -_slideBarXOffset - 5, _slideBarYOffset, 1.0); + + case SliderOpen.TOP_TO_BOTTOM: + return Matrix4.translationValues(0, _slideBarYOffset - 20, 1.0); + + default: + return Matrix4.translationValues(0, 0, 1.0); + } + } + + @override + void dispose() { + super.dispose(); + _animationController.dispose(); + } }