Skip to content

Commit

Permalink
Add width, minWidth and maxWidth properties on NavigationPane (bdluka…
Browse files Browse the repository at this point in the history
  • Loading branch information
WinXaito committed Nov 27, 2021
1 parent ba10fb2 commit 6420ece
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
41 changes: 39 additions & 2 deletions lib/src/controls/navigation/navigation_view/pane.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class NavigationPane with Diagnosticable {
this.key,
this.selected,
this.onChanged,
this.width,
this.maxWidth,
this.minWidth,
this.header,
this.items = const [],
this.footerItems = const [],
Expand All @@ -81,7 +84,8 @@ class NavigationPane with Diagnosticable {
this.menuButton,
this.scrollController,
this.indicatorBuilder = defaultNavigationIndicator,
}) : assert(selected == null || selected >= 0);
}) : assert(selected == null || selected >= 0),
assert(minWidth == null || maxWidth == null || minWidth <= maxWidth);

final Key? key;

Expand All @@ -97,6 +101,31 @@ class NavigationPane with Diagnosticable {
/// is null
final Widget? menuButton;

/// The width of the pane.
///
/// If the value is null, [_kOpenNavigationPanelWidth] is used.
/// The width can be based on MediaQuery and used
/// with [minWidth] and [maxWidth].
///
/// Only used when the pane is open.
final double? width;

/// The minimum width of the pane.
///
/// If width is smaller than minWidth, minWidth is used as width.
/// minWidth must be smaller or equal to maxWidth.
///
/// Only used when the pane is open.
final double? minWidth;

/// The maximum width of the pane.
///
/// If width is greater than maxWidth, maxWidth is used as width.
/// maxWidth must be greater or equal than minWidth.
///
/// Only used when the pane is open.
final double? maxWidth;

/// The header of the pane.
///
/// Usually a [Text] or an [Image].
Expand Down Expand Up @@ -543,11 +572,19 @@ class _OpenNavigationPane extends StatelessWidget {
}
return const SizedBox.shrink();
}();
var paneWidth = pane.width ?? _kOpenNavigationPanelWidth;
if (pane.maxWidth != null && paneWidth > pane.maxWidth!) {
paneWidth = pane.maxWidth!;
}
if (pane.minWidth != null && paneWidth < pane.minWidth!) {
paneWidth = pane.minWidth!;
}

return AnimatedContainer(
key: paneKey,
duration: theme.animationDuration ?? Duration.zero,
curve: theme.animationCurve ?? Curves.linear,
width: _kOpenNavigationPanelWidth,
width: paneWidth,
child: pane.indicatorBuilder(
context: context,
pane: pane,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/controls/navigation/navigation_view/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ class NavigationViewState extends State<NavigationView> {
autoSuggestBox: pane.autoSuggestBox,
autoSuggestBoxReplacement: pane.autoSuggestBoxReplacement,
footerItems: pane.footerItems,
width: pane.width,
minWidth: pane.minWidth,
maxWidth: pane.maxWidth,
header: pane.header,
items: pane.items,
key: pane.key,
Expand Down

0 comments on commit 6420ece

Please sign in to comment.