diff --git a/lib/flutter_slider_drawer.dart b/lib/flutter_slider_drawer.dart index 2da0bcd..4d65686 100644 --- a/lib/flutter_slider_drawer.dart +++ b/lib/flutter_slider_drawer.dart @@ -1,4 +1,4 @@ library flutter_slider_drawer; -export 'package:flutter_slider_drawer/src/slider_open.dart'; +export 'package:flutter_slider_drawer/src/slider_direction.dart'; export 'package:flutter_slider_drawer/src/slider.dart'; diff --git a/lib/src/app_bar.dart b/lib/src/app_bar.dart new file mode 100644 index 0000000..f1868d5 --- /dev/null +++ b/lib/src/app_bar.dart @@ -0,0 +1,76 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_slider_drawer/src/slider_direction.dart'; + +class SliderAppBar extends StatelessWidget { + final EdgeInsets appBarPadding; + final Color appBarColor; + final Widget drawerIcon; + final Color splashColor; + final Color drawerIconColor; + final double drawerIconSize; + final double appBarHeight; + final AnimationController animationController; + final VoidCallback onTap; + final Widget title; + final bool isTitleCenter; + final Widget trailing; + final SlideDirection slideDirection; + + const SliderAppBar( + {Key key, + this.appBarPadding, + this.appBarColor, + this.drawerIcon, + this.splashColor, + this.drawerIconColor, + this.drawerIconSize, + this.animationController, + this.onTap, + this.title, + this.isTitleCenter, + this.trailing, + this.slideDirection, this.appBarHeight}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + height: appBarHeight, + padding: appBarPadding ?? const EdgeInsets.only(top: 24), + color: appBarColor, + child: Row( + children: appBar(), + ), + ); + } + + List appBar() { + List list = [ + drawerIcon ?? + IconButton( + splashColor: splashColor ?? Colors.black, + icon: AnimatedIcon( + icon: AnimatedIcons.menu_close, + color: drawerIconColor, + size: drawerIconSize, + progress: animationController), + onPressed: () => onTap()), + Expanded( + child: isTitleCenter + ? Center( + child: title, + ) + : title, + ), + trailing ?? + SizedBox( + width: 35, + ) + ]; + + if (slideDirection == SlideDirection.RIGHT_TO_LEFT) { + return list.reversed.toList(); + } + return list; + } +} diff --git a/lib/src/helper/utils.dart b/lib/src/helper/utils.dart new file mode 100644 index 0000000..75de548 --- /dev/null +++ b/lib/src/helper/utils.dart @@ -0,0 +1,36 @@ +import 'dart:ui'; + +import 'package:flutter_slider_drawer/flutter_slider_drawer.dart'; + +class Utils { + /// + /// This method get Offset base on [sliderOpen] type + /// + + static Offset getOffsetValues(SlideDirection direction, double value) { + switch (direction) { + case SlideDirection.LEFT_TO_RIGHT: + return Offset(value, 0); + case SlideDirection.RIGHT_TO_LEFT: + return Offset(-value, 0); + case SlideDirection.TOP_TO_BOTTOM: + return Offset(0, value); + default: + return Offset(value, 0); + } + } + + static Offset getOffsetValueForShadow( + SlideDirection direction, double value, double slideOpenWidth) { + switch (direction) { + case SlideDirection.LEFT_TO_RIGHT: + return Offset(value - (slideOpenWidth > 50 ? 20 : 10), 0); + case SlideDirection.RIGHT_TO_LEFT: + return Offset(-value - 5, 0); + case SlideDirection.TOP_TO_BOTTOM: + return Offset(0, value - (slideOpenWidth > 50 ? 15 : 5)); + default: + return Offset(value - 30.0, 0); + } + } +} diff --git a/lib/src/menu_bar.dart b/lib/src/menu_bar.dart new file mode 100644 index 0000000..744e45f --- /dev/null +++ b/lib/src/menu_bar.dart @@ -0,0 +1,34 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_slider_drawer/src/slider_direction.dart'; + +/// +/// Build and Align the Menu widget based on the slide open type +/// +class SlideMenuBar extends StatelessWidget { + final SlideDirection slideDirection; + final double sliderMenuOpenSize; + final Widget sliderMenu; + + const SlideMenuBar( + {Key key, this.slideDirection, this.sliderMenuOpenSize, this.sliderMenu}) + : super(key: key); + + @override + Widget build(BuildContext context) { + var container = Container( + width: sliderMenuOpenSize, + child: sliderMenu, + ); + switch (slideDirection) { + case SlideDirection.LEFT_TO_RIGHT: + return container; + break; + case SlideDirection.RIGHT_TO_LEFT: + return Positioned(right: 0, top: 0, bottom: 0, child: container); + case SlideDirection.TOP_TO_BOTTOM: + return Positioned(right: 0, left: 0, top: 0, child: container); + break; + } + return Container(); + } +} diff --git a/lib/src/slider.dart b/lib/src/slider.dart index 09a2246..4eddef0 100644 --- a/lib/src/slider.dart +++ b/lib/src/slider.dart @@ -1,6 +1,9 @@ import 'package:flutter/animation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_slider_drawer/flutter_slider_drawer.dart'; +import 'package:flutter_slider_drawer/src/app_bar.dart'; +import 'package:flutter_slider_drawer/src/menu_bar.dart'; +import 'package:flutter_slider_drawer/src/helper/utils.dart'; +import 'package:flutter_slider_drawer/src/slider_direction.dart'; class SliderMenuContainer extends StatefulWidget { final Widget sliderMenu; @@ -9,6 +12,7 @@ class SliderMenuContainer extends StatefulWidget { final double sliderMenuOpenSize; final double sliderMenuCloseSize; + final bool hasAppBar; final Color drawerIconColor; final Widget drawerIcon; final double drawerIconSize; @@ -41,13 +45,14 @@ class SliderMenuContainer extends StatefulWidget { this.appBarPadding, this.title, this.drawerIconSize = 27, - this.appBarHeight, + this.appBarHeight = 70, this.sliderMenuCloseSize = 0, this.slideDirection = SlideDirection.LEFT_TO_RIGHT, this.isShadow = false, this.shadowColor = Colors.grey, this.shadowBlurRadius = 25.0, this.shadowSpreadRadius = 5.0, + this.hasAppBar = true, }) : assert(sliderMenu != null), assert(sliderMain != null), super(key: key); @@ -66,14 +71,13 @@ class SliderMenuContainerState extends State /// check whether drawer is open bool get isDrawerOpen => _animationDrawerController.isCompleted; + /// it's provide [animationController] for handle and lister drawer animation AnimationController get animationController => _animationDrawerController; /// Toggle drawer - void toggle() { - _animationDrawerController.isCompleted - ? _animationDrawerController.reverse() - : _animationDrawerController.forward(); - } + void toggle() => _animationDrawerController.isCompleted + ? _animationDrawerController.reverse() + : _animationDrawerController.forward(); /// Open drawer void openDrawer() => _animationDrawerController.forward(); @@ -102,16 +106,20 @@ class SliderMenuContainerState extends State return Container( child: Stack(children: [ /// Display Menu - menuWidget(), + SlideMenuBar( + slideDirection: widget.slideDirection, + sliderMenu: widget.sliderMenu, + sliderMenuOpenSize: widget.sliderMenuOpenSize, + ), - /// Dev -Displaying the shadow + /// Displaying the shadow if (widget.isShadow) ...[ AnimatedBuilder( animation: _animationDrawerController, builder: (anim, child) { return Transform.translate( - offset: getOffsetValueForShadow( - widget.slideDirection, animation.value), + offset: Utils.getOffsetValueForShadow(widget.slideDirection, + animation.value, widget.sliderMenuOpenSize), child: child, ); return child; @@ -125,8 +133,8 @@ class SliderMenuContainerState extends State 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 + 15.0, // Move to right 15 horizontally + 15.0, // Move to bottom 15 Vertically ), ) ]), @@ -134,12 +142,13 @@ class SliderMenuContainerState extends State ), ], - //Dev- Display Main Screen + //Display Main Screen AnimatedBuilder( animation: _animationDrawerController, builder: (anim, child) { return Transform.translate( - offset: getOffsetValues(widget.slideDirection, animation.value), + offset: + Utils.getOffsetValues(widget.slideDirection, animation.value), child: child, ); }, @@ -149,13 +158,22 @@ class SliderMenuContainerState extends State color: widget.appBarColor, child: Column( children: [ - Container( - padding: widget.appBarPadding ?? const EdgeInsets.only(top: 24), - color: widget.appBarColor, - child: Row( - children: appBar(), + if (widget.hasAppBar) + SliderAppBar( + slideDirection: widget.slideDirection, + onTap: () => toggle(), + appBarHeight: widget.appBarHeight, + animationController: _animationDrawerController, + appBarColor: widget.appBarColor, + appBarPadding: widget.appBarPadding, + drawerIcon: widget.drawerIcon, + drawerIconColor: widget.drawerIconColor, + drawerIconSize: widget.drawerIconSize, + isTitleCenter: widget.isTitleCenter, + splashColor: widget.splashColor, + title: widget.title ?? '', + trailing: widget.trailing, ), - ), Expanded(child: widget.sliderMain), ], ), @@ -164,99 +182,6 @@ class SliderMenuContainerState extends State ])); } - List appBar() { - List list = [ - widget.drawerIcon ?? - IconButton( - splashColor: widget.splashColor ?? Colors.black, - icon: AnimatedIcon( - icon: AnimatedIcons.menu_close, - color: widget.drawerIconColor, - size: widget.drawerIconSize, - progress: _animationDrawerController), - onPressed: () => toggle()), - Expanded( - child: widget.isTitleCenter - ? Center( - child: widget.title, - ) - : widget.title, - ), - widget.trailing ?? - SizedBox( - width: 35, - ) - ]; - - if (widget.slideDirection == SlideDirection.RIGHT_TO_LEFT) { - return list.reversed.toList(); - } - return list; - } - - /// Build and Align the Menu widget based on the slide open type - menuWidget() { - switch (widget.slideDirection) { - case SlideDirection.LEFT_TO_RIGHT: - return Container( - width: widget.sliderMenuOpenSize, - child: widget.sliderMenu, - ); - break; - case SlideDirection.RIGHT_TO_LEFT: - return Positioned( - right: 0, - top: 0, - bottom: 0, - child: Container( - width: widget.sliderMenuOpenSize, - child: widget.sliderMenu, - ), - ); - case SlideDirection.TOP_TO_BOTTOM: - return Positioned( - right: 0, - left: 0, - top: 0, - child: Container( - width: widget.sliderMenuOpenSize, - child: widget.sliderMenu, - ), - ); - break; - } - } - - /// - /// This method get Offset base on [sliderOpen] type - /// - - Offset getOffsetValues(SlideDirection direction, double value) { - switch (direction) { - case SlideDirection.LEFT_TO_RIGHT: - return Offset(value, 0); - case SlideDirection.RIGHT_TO_LEFT: - return Offset(-value, 0); - case SlideDirection.TOP_TO_BOTTOM: - return Offset(0, value); - default: - return Offset(value, 0); - } - } - - Offset getOffsetValueForShadow(SlideDirection direction, double value) { - switch (direction) { - case SlideDirection.LEFT_TO_RIGHT: - return Offset(value - (widget.sliderMenuOpenSize > 50 ? 20 : 10), 0); - case SlideDirection.RIGHT_TO_LEFT: - return Offset(-value - 5, 0); - case SlideDirection.TOP_TO_BOTTOM: - return Offset(0, value - (widget.sliderMenuOpenSize > 50 ? 15 : 5)); - default: - return Offset(value - 30.0, 0); - } - } - @override void dispose() { super.dispose(); diff --git a/lib/src/slider_open.dart b/lib/src/slider_direction.dart similarity index 100% rename from lib/src/slider_open.dart rename to lib/src/slider_direction.dart