diff --git a/example/lib/screens/navigation/tree_view.dart b/example/lib/screens/navigation/tree_view.dart index 6ea84d75..7df0b6eb 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( @@ -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}'); + }, + ), + ), ], ); } @@ -316,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 d81049dc..f1144437 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(), ), ), ),