From 260b6368fd95c0e3e188b11251a25cea93eba39f Mon Sep 17 00:00:00 2001 From: BranislavMateas Date: Wed, 27 Jul 2022 19:39:44 +0200 Subject: [PATCH 1/2] added feature where you can add custom collapse breakpoint --- lib/src/side_menu.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/side_menu.dart b/lib/src/side_menu.dart index f84cd48..2d46860 100644 --- a/lib/src/side_menu.dart +++ b/lib/src/side_menu.dart @@ -37,6 +37,9 @@ class SideMenu extends StatefulWidget { /// Duration of [displayMode] toggling duration final Duration? displayModeToggleDuration; + /// Width when will our open menu collapse into the compact one + final int? sideMenuBreakpoint; + /// ### Easy Sidemenu widget /// /// Sidemenu is a menu that is usually located @@ -52,6 +55,7 @@ class SideMenu extends StatefulWidget { this.onDisplayModeChanged, this.displayModeToggleDuration, this.alwaysShowFooter = false, + this.sideMenuBreakpoint = 600, }) : super(key: key); @override @@ -62,18 +66,21 @@ class _SideMenuState extends State { double _currentWidth = 0; late bool showToggle; late bool alwaysShowFooter; + late int sideMenuBreakpoint; @override void initState() { super.initState(); showToggle = widget.showToggle ?? false; alwaysShowFooter = widget.alwaysShowFooter ?? false; + sideMenuBreakpoint = widget.sideMenuBreakpoint ?? 600; } @override void didUpdateWidget(covariant SideMenu oldWidget) { showToggle = widget.showToggle ?? false; alwaysShowFooter = widget.alwaysShowFooter ?? false; + sideMenuBreakpoint = widget.sideMenuBreakpoint ?? 600; super.didUpdateWidget(oldWidget); } @@ -86,13 +93,13 @@ class _SideMenuState extends State { /// 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 > sideMenuBreakpoint && 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 <= sideMenuBreakpoint && Global.displayModeState.value != SideMenuDisplayMode.compact) { Global.displayModeState.change(SideMenuDisplayMode.compact); _notifyParent(); From 97d8a081a0e05cdc9417c13d6eb7ec090d258177 Mon Sep 17 00:00:00 2001 From: BranislavMateas Date: Wed, 27 Jul 2022 20:44:45 +0200 Subject: [PATCH 2/2] fixed naming --- lib/src/side_menu.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/src/side_menu.dart b/lib/src/side_menu.dart index 2d46860..ba94add 100644 --- a/lib/src/side_menu.dart +++ b/lib/src/side_menu.dart @@ -38,7 +38,7 @@ class SideMenu extends StatefulWidget { final Duration? displayModeToggleDuration; /// Width when will our open menu collapse into the compact one - final int? sideMenuBreakpoint; + final int? collapseWidth; /// ### Easy Sidemenu widget /// @@ -55,7 +55,7 @@ class SideMenu extends StatefulWidget { this.onDisplayModeChanged, this.displayModeToggleDuration, this.alwaysShowFooter = false, - this.sideMenuBreakpoint = 600, + this.collapseWidth = 600, }) : super(key: key); @override @@ -66,21 +66,21 @@ class _SideMenuState extends State { double _currentWidth = 0; late bool showToggle; late bool alwaysShowFooter; - late int sideMenuBreakpoint; + late int collapseWidth; @override void initState() { super.initState(); showToggle = widget.showToggle ?? false; alwaysShowFooter = widget.alwaysShowFooter ?? false; - sideMenuBreakpoint = widget.sideMenuBreakpoint ?? 600; + collapseWidth = widget.collapseWidth ?? 600; } @override void didUpdateWidget(covariant SideMenu oldWidget) { showToggle = widget.showToggle ?? false; alwaysShowFooter = widget.alwaysShowFooter ?? false; - sideMenuBreakpoint = widget.sideMenuBreakpoint ?? 600; + collapseWidth = widget.collapseWidth ?? 600; super.didUpdateWidget(oldWidget); } @@ -93,13 +93,13 @@ class _SideMenuState extends State { /// 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 > sideMenuBreakpoint && + if (MediaQuery.of(context).size.width > collapseWidth && Global.displayModeState.value != SideMenuDisplayMode.open) { Global.displayModeState.change(SideMenuDisplayMode.open); _notifyParent(); return Global.style.openSideMenuWidth ?? 300; } - if (MediaQuery.of(context).size.width <= sideMenuBreakpoint && + if (MediaQuery.of(context).size.width <= collapseWidth && Global.displayModeState.value != SideMenuDisplayMode.compact) { Global.displayModeState.change(SideMenuDisplayMode.compact); _notifyParent();