Skip to content

Commit

Permalink
Add alwaysShowFooter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamalianpour committed Jul 21, 2022
1 parent 2c49e1d commit 185ad9f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [0.3.2]
* Fix delete menu from widget tree - [#15](https://github.com/Jamalianpour/easy_sidemenu/pull/15)
* Add alwaysShowFooter

## [0.3.1]
* Fix null exception on `onDisplayModeChanged`
* Fix `WidgetsBinding.instance` null checker in flutter 3

## [0.3.0]
* Add listener to `SideMenuDisplayMode` changed
* Add toggle button to open and compact sidemenu
Expand Down
43 changes: 25 additions & 18 deletions lib/src/side_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class SideMenu extends StatefulWidget {
/// If the display mode is auto, this button will not be displayed
final bool? showToggle;

/// By default footer only shown when display mode is open
/// If you want always shown footer set it to true
final bool? alwaysShowFooter;

/// Notify when [SideMenuDisplayMode] changed
final ValueChanged<SideMenuDisplayMode>? onDisplayModeChanged;

Expand All @@ -44,9 +48,10 @@ class SideMenu extends StatefulWidget {
this.title,
this.footer,
this.style,
this.showToggle,
this.showToggle = false,
this.onDisplayModeChanged,
this.displayModeToggleDuration,
this.alwaysShowFooter = false,
}) : super(key: key);

@override
Expand All @@ -56,11 +61,20 @@ class SideMenu extends StatefulWidget {
class _SideMenuState extends State<SideMenu> {
double _currentWidth = 0;
late bool showToggle;
late bool alwaysShowFooter;

@override
void initState() {
super.initState();
showToggle = widget.showToggle ?? false;
alwaysShowFooter = widget.alwaysShowFooter ?? false;
}

@override
void didUpdateWidget(covariant SideMenu oldWidget) {
showToggle = widget.showToggle ?? false;
alwaysShowFooter = widget.alwaysShowFooter ?? false;
super.didUpdateWidget(oldWidget);
}

void _notifyParent() {
Expand All @@ -72,19 +86,13 @@ class _SideMenuState extends State<SideMenu> {
/// Set [SideMenu] width according to displayMode and notify parent widget
double _widthSize(SideMenuDisplayMode mode, BuildContext context) {
if (mode == SideMenuDisplayMode.auto) {
if (MediaQuery
.of(context)
.size
.width > 600 &&
if (MediaQuery.of(context).size.width > 600 &&
Global.displayModeState.value != SideMenuDisplayMode.open) {
Global.displayModeState.change(SideMenuDisplayMode.open);
_notifyParent();
return Global.style.openSideMenuWidth ?? 300;
}
if (MediaQuery
.of(context)
.size
.width <= 600 &&
if (MediaQuery.of(context).size.width <= 600 &&
Global.displayModeState.value != SideMenuDisplayMode.compact) {
Global.displayModeState.change(SideMenuDisplayMode.compact);
_notifyParent();
Expand Down Expand Up @@ -136,10 +144,7 @@ class _SideMenuState extends State<SideMenu> {
return AnimatedContainer(
duration: _toggleDuration(),
width: _currentWidth,
height: MediaQuery
.of(context)
.size
.height,
height: MediaQuery.of(context).size.height,
decoration: _decoration(widget.style),
child: Stack(
children: [
Expand All @@ -156,17 +161,19 @@ class _SideMenuState extends State<SideMenu> {
],
),
),
if (widget.footer != null &&
Global.displayModeState.value != SideMenuDisplayMode.compact)
if ((widget.footer != null &&
Global.displayModeState.value !=
SideMenuDisplayMode.compact) ||
(widget.footer != null && alwaysShowFooter))
Align(alignment: Alignment.bottomCenter, child: widget.footer!),
if (Global.style.displayMode != SideMenuDisplayMode.auto &&
showToggle)
Padding(
padding: EdgeInsets.symmetric(
horizontal:
Global.displayModeState.value == SideMenuDisplayMode.open
? 0
: 4,
Global.displayModeState.value == SideMenuDisplayMode.open
? 0
: 4,
vertical: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
Expand Down

0 comments on commit 185ad9f

Please sign in to comment.