From b844e1147ec69b21da1d865684fe423ffe9b39fb Mon Sep 17 00:00:00 2001 From: maxu Date: Sun, 11 Feb 2024 17:22:53 +0800 Subject: [PATCH 1/2] TreeView item add disabled option: Whether the current item is disabled --- example/lib/screens/navigation/tree_view.dart | 3 ++- lib/src/controls/navigation/tree_view.dart | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/example/lib/screens/navigation/tree_view.dart b/example/lib/screens/navigation/tree_view.dart index 6ea84d754..bc9215737 100644 --- a/example/lib/screens/navigation/tree_view.dart +++ b/example/lib/screens/navigation/tree_view.dart @@ -122,7 +122,7 @@ TreeView( // Do your fetching... await Future.delayed(const Duration(seconds: 2)); - + // ...and add the fetched nodes. item.children.addAll([ TreeViewItem( @@ -231,6 +231,7 @@ TreeView( TreeViewItem( content: const Text('Home Remodel'), value: 'home_remodel', + disabled: true, children: [ TreeViewItem( content: const Text('Contractor Contact Info'), diff --git a/lib/src/controls/navigation/tree_view.dart b/lib/src/controls/navigation/tree_view.dart index d81049dc2..39ab15b7c 100644 --- a/lib/src/controls/navigation/tree_view.dart +++ b/lib/src/controls/navigation/tree_view.dart @@ -146,6 +146,10 @@ class TreeViewItem with Diagnosticable { /// item is going to be one of the selected items bool? selected; + /// Whether the current item is disabled. + /// + bool? disabled; + /// Called when this item is invoked /// /// This item is passed to the callback. @@ -210,6 +214,7 @@ class TreeViewItem with Diagnosticable { this.collapsable = true, bool? expanded, this.selected = false, + this.disabled = false, this.onInvoked, this.onExpandToggle, this.gestures = const {}, @@ -1031,7 +1036,9 @@ class _TreeViewItem extends StatelessWidget { child: ExcludeFocus( child: Checkbox( checked: item.selected, - onChanged: (value) => _onCheckboxInvoked(), + onChanged: item.disabled ?? false + ? null + : (value) => _onCheckboxInvoked(), ), ), ), From 3df950b709e23f6bd7faae8a97de53a81d4a422d Mon Sep 17 00:00:00 2001 From: maxu Date: Tue, 13 Feb 2024 00:58:17 +0800 Subject: [PATCH 2/2] 1.set TreeViewItem's disabled option to non-nullable 2.add TreeView example with disabled option --- example/lib/screens/navigation/tree_view.dart | 95 ++++++++++++++++++- lib/src/controls/navigation/tree_view.dart | 2 +- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/example/lib/screens/navigation/tree_view.dart b/example/lib/screens/navigation/tree_view.dart index bc9215737..7df0b6eb4 100644 --- a/example/lib/screens/navigation/tree_view.dart +++ b/example/lib/screens/navigation/tree_view.dart @@ -219,6 +219,67 @@ TreeView( }, ), ), + subtitle( + content: const Text('A TreeView with checkbox disabled'), + ), + CardHighlight( + codeSnippet: r'''late final disabledItems = [ + TreeViewItem( + content: const Text('Personal Documents'), + value: 'personal_docs', + children: [ + TreeViewItem( + content: const Text('Home Remodel'), + value: 'home_remodel', + disabled: true, + children: [ + TreeViewItem( + content: const Text('Contractor Contact Info'), + value: 'contr_cont_inf', + ), + TreeViewItem( + content: const Text('Paint Color Scheme'), + value: 'paint_color_scheme', + disabled: true, + ), + ], + ), + TreeViewItem( + content: const Text('Tax Documents'), + value: 'tax_docs', + children: [ + TreeViewItem(content: const Text('2017'), value: "tax_2017"), + TreeViewItem(content: const Text('Current Year'), value: "tax_cur"), + ], + ), + ], + ), +]; + +TreeView( + selectionMode: TreeViewSelectionMode.multiple, + items: disabledItems, + onItemInvoked: (item, reason) async => + debugPrint('onItemInvoked(reason=$reason): $item'), + onSelectionChanged: (selectedItems) async => debugPrint( + 'onSelectionChanged: ${selectedItems.map((i) => i.value)}'), + onSecondaryTap: (item, details) async { + debugPrint('onSecondaryTap $item at ${details.globalPosition}'); + }, +) +''', + child: TreeView( + selectionMode: TreeViewSelectionMode.multiple, + items: disabledItems, + onItemInvoked: (item, reason) async => + debugPrint('onItemInvoked(reason=$reason): $item'), + onSelectionChanged: (selectedItems) async => debugPrint( + 'onSelectionChanged: ${selectedItems.map((i) => i.value)}'), + onSecondaryTap: (item, details) async { + debugPrint('onSecondaryTap $item at ${details.globalPosition}'); + }, + ), + ), ], ); } @@ -231,7 +292,6 @@ TreeView( TreeViewItem( content: const Text('Home Remodel'), value: 'home_remodel', - disabled: true, children: [ TreeViewItem( content: const Text('Contractor Contact Info'), @@ -317,4 +377,37 @@ TreeView( }, ), ]; + + late final disabledItems = [ + TreeViewItem( + content: const Text('Personal Documents'), + value: 'personal_docs', + children: [ + TreeViewItem( + content: const Text('Home Remodel'), + value: 'home_remodel', + disabled: true, + children: [ + TreeViewItem( + content: const Text('Contractor Contact Info'), + value: 'contr_cont_inf', + ), + TreeViewItem( + content: const Text('Paint Color Scheme'), + value: 'paint_color_scheme', + disabled: true, + ), + ], + ), + TreeViewItem( + content: const Text('Tax Documents'), + value: 'tax_docs', + children: [ + TreeViewItem(content: const Text('2017'), value: "tax_2017"), + TreeViewItem(content: const Text('Current Year'), value: "tax_cur"), + ], + ), + ], + ), + ]; } diff --git a/lib/src/controls/navigation/tree_view.dart b/lib/src/controls/navigation/tree_view.dart index 39ab15b7c..f11444373 100644 --- a/lib/src/controls/navigation/tree_view.dart +++ b/lib/src/controls/navigation/tree_view.dart @@ -148,7 +148,7 @@ class TreeViewItem with Diagnosticable { /// Whether the current item is disabled. /// - bool? disabled; + bool disabled; /// Called when this item is invoked ///