Skip to content

Commit

Permalink
feat: expose NavigationPage navigator observers & onPopPage
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi committed Jul 12, 2023
1 parent 0bee47a commit 9f7a7f9
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions lib/src/widgets/navi_rail/yaru_navigation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ class YaruNavigationPage extends StatefulWidget {
this.leading,
this.trailing,
this.navigatorKey,
this.navigatorObservers = const <NavigatorObserver>[],
this.initialRoute,
this.onGenerateRoute,
this.onUnknownRoute,
this.onPopPage,
}) : assert(initialIndex == null || controller == null),
assert((length == null) != (controller == null));

Expand Down Expand Up @@ -67,15 +69,39 @@ class YaruNavigationPage extends StatefulWidget {
/// A key to use when building the [Navigator] widget.
final GlobalKey<NavigatorState>? navigatorKey;

/// The list of observers for the [Navigator] created in this page.
///
/// See also:
/// * [Navigator.observers]
final List<NavigatorObserver> navigatorObservers;

/// The route name for the initial route.
///
/// See also:
/// * [Navigator.initialRoute]
final String? initialRoute;

/// Called to generate a route for a given [RouteSettings].
///
/// See also:
/// * [Navigator.onGenerateRoute]
final RouteFactory? onGenerateRoute;

/// Called when [onGenerateRoute] fails to generate a route.
///
/// See also:
/// * [Navigator.onUnknownRoute]
final RouteFactory? onUnknownRoute;

/// Called when a dynamically pushed route is popped off.
///
/// This callback is responsible for calling [Route.didPop] and returning
/// whether this pop is successful.
///
/// See also:
/// * [Navigator.onPopPage]
final PopPageCallback? onPopPage;

@override
State<YaruNavigationPage> createState() => _YaruNavigationPageState();
}
Expand Down Expand Up @@ -202,8 +228,9 @@ class _YaruNavigationPageState extends State<YaruNavigationPage> {
initialRoute: widget.initialRoute,
onGenerateRoute: widget.onGenerateRoute,
onUnknownRoute: widget.onUnknownRoute,
onPopPage: (route, result) => route.didPop(result),
observers: [HeroController()],
onPopPage: (route, result) =>
widget.onPopPage?.call(route, result) ?? route.didPop(result),
observers: [...widget.navigatorObservers, HeroController()],
),
),
);
Expand Down

0 comments on commit 9f7a7f9

Please sign in to comment.