navigate method
Navigates using the given action.
If the software keyboard is visible, it is dismissed first and the navigation is deferred until the keyboard dismiss animation completes.
Analytics events are emitted only when an analyticsSink was provided
to the constructor; otherwise navigation runs without analytics.
Implementation
bool navigate(
NavigationType action, {
SamePageNavigationReplaceType samePageReplaceType =
const SamePageNavigationReplaceTop(),
}) {
final hasKeyboard =
(WidgetsBinding
.instance
.platformDispatcher
.implicitView
?.viewInsets
.bottom ??
0) >
0;
if (!action.skipKeyboardDismissal && hasKeyboard) {
FocusManager.instance.primaryFocus?.unfocus();
_pendingNavigations.add(
(action: action, samePageReplaceType: samePageReplaceType),
);
_pendingKeyboardObserver ??= _KeyboardDismissObserver(
onDismissed: () {
_pendingKeyboardObserver = null;
final navigations = List.of(_pendingNavigations);
_pendingNavigations.clear();
for (final pending in navigations) {
_performNavigation(
pending.action,
samePageReplaceType: pending.samePageReplaceType,
);
}
},
);
return true;
}
return _performNavigation(action, samePageReplaceType: samePageReplaceType);
}