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

feat: Added NavigationView.onItemPressed callback, called when item is on tap. #1067

Merged
merged 2 commits into from
May 31, 2024
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
## NEXT
* fix: Scroll issue in `DatePicker`. ([#1054](https://github.com/bdlukaa/fluent_ui/issues/1054))
* feat: Add `NumberBox.textInputAction` and `NumberBox.onEditingComplete` ([#1063](https://github.com/bdlukaa/fluent_ui/pull/1063))
* feat: Added `NavigationView.onItemPressed` callback, called when the item is on tap.
bdlukaa marked this conversation as resolved.
Show resolved Hide resolved

## 4.8.7

* fix: A child of `Button` has an unbound height constraint. ([#1039](https://github.com/bdlukaa/fluent_ui/issues/1039))
* feat: Added `DatePicker.fieldFlex` to control the width proportion of each field. ([#1053](https://github.com/bdlukaa/fluent_ui/pull/1053))
* fix: `Slider` thumb is correct rendered when it's on the edges. ([#1046](https://github.com/bdlukaa/fluent_ui/pull/1046)
* fix: `Slider` thumb is correct rendered when it's on the edges. ([#1046](https://github.com/bdlukaa/fluent_ui/pull/1046))
* feat: Added `TabView.addIconBuilder` ([#1047](https://github.com/bdlukaa/fluent_ui/pull/1047))

## 4.8.6
Expand Down
20 changes: 20 additions & 0 deletions example/lib/screens/navigation/navigation_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ NavigationView(
),
pane: NavigationPane(
selected: topIndex,
onItemPressed: (index) {
// Do anything you want to do, such as:
if (index == topIndex) {
if (displayMode == PaneDisplayMode.open) {
setState(() => this.displayMode = PaneDisplayMode.compact);
} else if (displayMode == PaneDisplayMode.compact) {
setState(() => this.displayMode = PaneDisplayMode.open);
}
}
},
onChanged: (index) => setState(() => topIndex = index),
displayMode: displayMode,
items: items,
Expand Down Expand Up @@ -329,6 +339,16 @@ NavigationView(
},
pane: NavigationPane(
selected: topIndex,
onItemPressed: (index) {
// Do anything you want to do, such as:
if (index == topIndex) {
if (displayMode == PaneDisplayMode.open) {
setState(() => this.displayMode = PaneDisplayMode.compact);
} else if (displayMode == PaneDisplayMode.compact) {
setState(() => this.displayMode = PaneDisplayMode.open);
}
}
},
onChanged: (index) => setState(() => topIndex = index),
displayMode: displayMode,
indicator: indicators[indicator],
Expand Down
9 changes: 9 additions & 0 deletions lib/src/controls/navigation/navigation_view/pane.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class NavigationPane with Diagnosticable {
this.key,
this.selected,
this.onChanged,
this.onItemPressed,
this.size,
this.header,
this.items = const [],
Expand Down Expand Up @@ -183,6 +184,9 @@ class NavigationPane with Diagnosticable {
/// Called when the current index changes.
final ValueChanged<int>? onChanged;

/// Called when the item is clicked.
bdlukaa marked this conversation as resolved.
Show resolved Hide resolved
final ValueChanged<int>? onItemPressed;

/// The scroll controller used by the pane when [displayMode] is
/// [PaneDisplayMode.compact] and [PaneDisplayMode.open].
///
Expand Down Expand Up @@ -223,6 +227,8 @@ class NavigationPane with Diagnosticable {
))
..add(IntProperty('selected', selected, ifNull: 'none'))
..add(ObjectFlagProperty('onChanged', onChanged, ifNull: 'disabled'))
..add(ObjectFlagProperty('onItemPressed', onItemPressed,
ifNull: 'disabled'))
..add(DiagnosticsProperty<ScrollController>(
'scrollController', scrollController))
..add(DiagnosticsProperty<NavigationPaneSize>('size', size))
Expand All @@ -232,6 +238,7 @@ class NavigationPane with Diagnosticable {
/// Changes the selected item to [item].
void changeTo(NavigationPaneItem item) {
final index = effectiveIndexOf(item);
if (!index.isNegative) onItemPressed?.call(index);
if (selected != index && !index.isNegative) onChanged?.call(index);
}

Expand Down Expand Up @@ -333,6 +340,7 @@ class NavigationPane with Diagnosticable {
other.autoSuggestBoxReplacement == autoSuggestBoxReplacement &&
other.selected == selected &&
other.onChanged == onChanged &&
other.onItemPressed == onItemPressed &&
other.scrollController == scrollController &&
other.indicator == indicator;
}
Expand All @@ -351,6 +359,7 @@ class NavigationPane with Diagnosticable {
autoSuggestBoxReplacement.hashCode ^
selected.hashCode ^
onChanged.hashCode ^
onItemPressed.hashCode ^
scrollController.hashCode ^
indicator.hashCode;
}
Expand Down
Loading