From 9f7a7f918b90c4fe14afef7d2dcace4dceceef40 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 12 Jul 2023 18:50:50 +0200 Subject: [PATCH] feat: expose NavigationPage navigator observers & onPopPage --- .../navi_rail/yaru_navigation_page.dart | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/src/widgets/navi_rail/yaru_navigation_page.dart b/lib/src/widgets/navi_rail/yaru_navigation_page.dart index 01e5583e0..6fd2835fd 100644 --- a/lib/src/widgets/navi_rail/yaru_navigation_page.dart +++ b/lib/src/widgets/navi_rail/yaru_navigation_page.dart @@ -28,9 +28,11 @@ class YaruNavigationPage extends StatefulWidget { this.leading, this.trailing, this.navigatorKey, + this.navigatorObservers = const [], this.initialRoute, this.onGenerateRoute, this.onUnknownRoute, + this.onPopPage, }) : assert(initialIndex == null || controller == null), assert((length == null) != (controller == null)); @@ -67,15 +69,39 @@ class YaruNavigationPage extends StatefulWidget { /// A key to use when building the [Navigator] widget. final GlobalKey? navigatorKey; + /// The list of observers for the [Navigator] created in this page. + /// + /// See also: + /// * [Navigator.observers] + final List 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 createState() => _YaruNavigationPageState(); } @@ -202,8 +228,9 @@ class _YaruNavigationPageState extends State { 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()], ), ), );