Skip to content

Commit

Permalink
Allow initial expansion of SidebarItem disclosure items (#514)
Browse files Browse the repository at this point in the history
* Allow initial expansion of SidebarItem disclosure items

* Update version to 2.0.9
  • Loading branch information
nu11ptr authored Aug 31, 2024
1 parent e35fdab commit 7f13dfd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.0.9]
### 🛠️ Updated 🛠️
* Add `expandDisclosureItems` flag to `SidebarItem` to optionally (default not changed) expand disclosure items initially

## [2.0.8]
### 🛠️ Updated 🛠️
* Fixed `SidebarItem` text overflowing.
Expand Down
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class _WidgetGalleryState extends State<WidgetGallery> {
label: Text('ResizablePane'),
),
],
expandDisclosureItems: true,
),
SidebarItem(
leading: MacosImageIcon(
Expand Down
8 changes: 8 additions & 0 deletions lib/src/layout/sidebar/sidebar_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SidebarItem with Diagnosticable {
this.focusNode,
this.semanticLabel,
this.disclosureItems,
this.expandDisclosureItems = false,
this.trailing,
});

Expand Down Expand Up @@ -58,6 +59,11 @@ class SidebarItem with Diagnosticable {
/// If non-null and [leading] is null, a local animated icon is created
final List<SidebarItem>? disclosureItems;

/// If true, the disclosure items will be expanded otherwise collapsed.
///
/// Defaults to false. There is no impact if [disclosureItems] is null.
final bool expandDisclosureItems;

/// An optional trailing widget.
///
/// Typically a text indicator of a count of items, like in this
Expand All @@ -77,6 +83,8 @@ class SidebarItem with Diagnosticable {
'disclosure items',
disclosureItems,
));
properties.add(
FlagProperty('expandDisclosureItems', value: expandDisclosureItems));
properties.add(DiagnosticsProperty<Widget?>('trailing', trailing));
}
}
8 changes: 6 additions & 2 deletions lib/src/layout/sidebar/sidebar_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,7 @@ class __DisclosureSidebarItemState extends State<_DisclosureSidebarItem>
late AnimationController _controller;
late Animation<double> _iconTurns;
late Animation<double> _heightFactor;

bool _isExpanded = false;
late bool _isExpanded;

bool get hasLeading => widget.item.leading != null;

Expand All @@ -389,6 +388,11 @@ class __DisclosureSidebarItemState extends State<_DisclosureSidebarItem>
_controller = AnimationController(duration: _kExpand, vsync: this);
_heightFactor = _controller.drive(_easeInTween);
_iconTurns = _controller.drive(_halfTween.chain(_easeInTween));

_isExpanded = widget.item.expandDisclosureItems;
if (_isExpanded) {
_controller.forward();
}
}

void _handleTap() {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: macos_ui
description: Flutter widgets and themes implementing the current macOS design language.
version: 2.0.8
version: 2.0.9
homepage: "https://macosui.dev"
repository: "https://github.com/GroovinChip/macos_ui"

Expand Down

0 comments on commit 7f13dfd

Please sign in to comment.