Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeView item add disabled option: Whether the current item is disabled #1023

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 94 additions & 1 deletion example/lib/screens/navigation/tree_view.dart
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

However, when the parent TreeViewItem is checked, all child TreeViewItems can still be selected.

In my application, if the parent TreeViewItem is disabled, then manually set the disabled property to true for all child elements.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be misleading. Maybe adding this to the documentation OR creating a new property (maybe disableChildren) that will disable the children if the parent is disabled?

Original file line number Diff line number Diff line change
Expand Up @@ -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}');
},
),
),
],
);
}
Expand All @@ -231,7 +292,6 @@ TreeView(
TreeViewItem(
content: const Text('Home Remodel'),
value: 'home_remodel',
disabled: true,
children: [
TreeViewItem(
content: const Text('Contractor Contact Info'),
Expand Down Expand Up @@ -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"),
],
),
],
),
];
}
2 changes: 1 addition & 1 deletion lib/src/controls/navigation/tree_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class TreeViewItem with Diagnosticable {

/// Whether the current item is disabled.
///
bool? disabled;
bool disabled;

/// Called when this item is invoked
///
Expand Down