Skip to content

Commit

Permalink
on route changed listener
Browse files Browse the repository at this point in the history
  • Loading branch information
g-apparence committed Oct 11, 2023
1 parent b3fa72b commit 539554a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/bart/bart_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BartScaffold extends StatefulWidget {
final BartBottomBar bottomBar;
final BartRouteBuilder routesBuilder;
final String? initialRoute;
final OnRouteChanged? onRouteChanged;
// appBar
final ValueNotifier<PreferredSizeWidget?> appBarNotifier;
final ValueNotifier<bool> showAppBarNotifier;
Expand All @@ -24,6 +25,7 @@ class BartScaffold extends StatefulWidget {
required this.routesBuilder,
this.initialRoute,
this.scaffoldOptions,
this.onRouteChanged,
bool showBottomBarOnStart = true,
}) : appBarNotifier = ValueNotifier(null),
showAppBarNotifier = ValueNotifier(false),
Expand Down
5 changes: 5 additions & 0 deletions lib/bart/router_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import 'package:bart/bart/widgets/nested_navigator.dart';

import 'bart_model.dart';

typedef OnRouteChanged = void Function(BartMenuRoute route);

class MenuRouter extends InheritedWidget {
final BartRouteBuilder routesBuilder;
final GlobalKey<NavigatorState> navigationKey;
final ValueNotifier<int> indexNotifier;
final ValueNotifier<BartMenuRouteType> routingTypeNotifier;
final OnRouteChanged? onRouteChanged;

const MenuRouter({
Key? key,
Expand All @@ -18,6 +21,7 @@ class MenuRouter extends InheritedWidget {
required this.navigationKey,
required this.indexNotifier,
required this.routingTypeNotifier,
this.onRouteChanged,
required Widget child,
}) : super(key: key, child: child);

Expand All @@ -28,6 +32,7 @@ class MenuRouter extends InheritedWidget {
WidgetsBinding.instance.addPostFrameCallback((_) {
indexNotifier.value = index;
routingTypeNotifier.value = route.type;
onRouteChanged?.call(route);
});
}

Expand Down

0 comments on commit 539554a

Please sign in to comment.