Skip to content

Commit

Permalink
feat: Added NavigationView.onItemPressed callback, called when item…
Browse files Browse the repository at this point in the history
… is on tap. (#1067)
  • Loading branch information
bdlukaa authored May 31, 2024
2 parents f60c41d + d6234ec commit 32ec723
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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 ([#1067](https://github.com/bdlukaa/fluent_ui/pull/1067))

## 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 an item is pressed.
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

0 comments on commit 32ec723

Please sign in to comment.