Skip to content

Commit 7f13dfd

Browse files
authored
Allow initial expansion of SidebarItem disclosure items (#514)
* Allow initial expansion of SidebarItem disclosure items * Update version to 2.0.9
1 parent e35fdab commit 7f13dfd

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [2.0.9]
2+
### 🛠️ Updated 🛠️
3+
* Add `expandDisclosureItems` flag to `SidebarItem` to optionally (default not changed) expand disclosure items initially
4+
15
## [2.0.8]
26
### 🛠️ Updated 🛠️
37
* Fixed `SidebarItem` text overflowing.

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class _WidgetGalleryState extends State<WidgetGallery> {
221221
label: Text('ResizablePane'),
222222
),
223223
],
224+
expandDisclosureItems: true,
224225
),
225226
SidebarItem(
226227
leading: MacosImageIcon(

lib/src/layout/sidebar/sidebar_item.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class SidebarItem with Diagnosticable {
1919
this.focusNode,
2020
this.semanticLabel,
2121
this.disclosureItems,
22+
this.expandDisclosureItems = false,
2223
this.trailing,
2324
});
2425

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

62+
/// If true, the disclosure items will be expanded otherwise collapsed.
63+
///
64+
/// Defaults to false. There is no impact if [disclosureItems] is null.
65+
final bool expandDisclosureItems;
66+
6167
/// An optional trailing widget.
6268
///
6369
/// Typically a text indicator of a count of items, like in this
@@ -77,6 +83,8 @@ class SidebarItem with Diagnosticable {
7783
'disclosure items',
7884
disclosureItems,
7985
));
86+
properties.add(
87+
FlagProperty('expandDisclosureItems', value: expandDisclosureItems));
8088
properties.add(DiagnosticsProperty<Widget?>('trailing', trailing));
8189
}
8290
}

lib/src/layout/sidebar/sidebar_items.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ class __DisclosureSidebarItemState extends State<_DisclosureSidebarItem>
378378
late AnimationController _controller;
379379
late Animation<double> _iconTurns;
380380
late Animation<double> _heightFactor;
381-
382-
bool _isExpanded = false;
381+
late bool _isExpanded;
383382

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

@@ -389,6 +388,11 @@ class __DisclosureSidebarItemState extends State<_DisclosureSidebarItem>
389388
_controller = AnimationController(duration: _kExpand, vsync: this);
390389
_heightFactor = _controller.drive(_easeInTween);
391390
_iconTurns = _controller.drive(_halfTween.chain(_easeInTween));
391+
392+
_isExpanded = widget.item.expandDisclosureItems;
393+
if (_isExpanded) {
394+
_controller.forward();
395+
}
392396
}
393397

394398
void _handleTap() {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: macos_ui
22
description: Flutter widgets and themes implementing the current macOS design language.
3-
version: 2.0.8
3+
version: 2.0.9
44
homepage: "https://macosui.dev"
55
repository: "https://github.com/GroovinChip/macos_ui"
66

0 commit comments

Comments
 (0)