Skip to content

Commit e3db5e6

Browse files
committed
feat: FlyoutController.close can now return a value to the previous route. (Fixes #1246)
1 parent c329ddb commit e3db5e6

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,27 @@
66
- feat: Added `WindowsIcon` and `WindowsIcons` ([#1237](https://github.com/bdlukaa/fluent_ui/pull/1237))
77
- fix: `Slider` label on drag ([#1248](https://github.com/bdlukaa/fluent_ui/issues/1248))
88
- fix: `closeAfterClick` at the item level is no longer ignored on `DropDownButton` ([#1245](https://github.com/bdlukaa/fluent_ui/issues/1245))
9+
- **MINOR BREAKING** feat: `FlyoutController.close` can now return a value to the previous route. ([#1246](https://github.com/bdlukaa/fluent_ui/issues/1246))
10+
Before:
11+
12+
```dart
13+
// normally close the flyout
14+
flyoutController.close();
915
16+
// forcefully close the flyout
17+
flyoutController.close(true);
18+
```
19+
20+
After:
21+
22+
```dart
23+
// normally close the flyout
24+
final result = flyoutController.close<String>('my result');
25+
26+
// forcefully close the flyout
27+
flyoutController.forceClose();
28+
```
29+
1030
## 4.12.0
1131

1232
- feat: Support Flutter 3.32

lib/src/controls/flyouts/flyout.dart

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -877,18 +877,37 @@ class FlyoutController with ChangeNotifier, WidgetsBindingObserver {
877877
/// be closed. It is a good practice to close the flyout before pushing new
878878
/// routes.
879879
///
880-
/// If [force] is true, the flyout is removed from the navigator stack without
881-
/// completing the transition.
882-
void close([bool force = false]) {
880+
/// See also:
881+
///
882+
/// * [forceClose], which forcefully closes the flyout without completing
883+
/// the transition.
884+
void close<T>([T? result]) {
883885
_ensureAttached();
884886
_ensureOpen();
885887
if (_route == null) return; // safe for release
886-
if (force) {
887-
_currentNavigator!.removeRoute(_route!);
888-
} else {
889-
_currentNavigator!.maybePop();
890-
}
888+
_currentNavigator!.maybePop(result);
889+
_route = _currentNavigator = null;
890+
}
891891

892+
/// Forcefully closes the flyout.
893+
///
894+
/// The flyout must be open, otherwise an error is thrown.
895+
///
896+
/// If any other route is pushed above the Flyout, this route is likely to
897+
/// be closed. It is a good practice to close the flyout before pushing new
898+
/// routes.
899+
///
900+
/// The flyout will be removed from the navigator stack without completing the
901+
/// transition.
902+
///
903+
/// See also:
904+
///
905+
/// * [close], which closes the flyout completing the transition.
906+
void forceClose() {
907+
_ensureAttached();
908+
_ensureOpen();
909+
if (_route == null) return; // safe for release
910+
_currentNavigator!.removeRoute(_route!);
892911
_route = _currentNavigator = null;
893912
}
894913

0 commit comments

Comments
 (0)