-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(navigator): add navigation observer to sync active tab
- Loading branch information
1 parent
69832ca
commit a492cf7
Showing
6 changed files
with
87 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import "dart:async"; | ||
|
||
import "package:auto_route/auto_route.dart"; | ||
import "package:flutter/widgets.dart"; | ||
import "package:flutter_riverpod/flutter_riverpod.dart"; | ||
import "package:riverpod_annotation/riverpod_annotation.dart"; | ||
|
||
import "navigation_controller.dart"; | ||
|
||
part "navigation_observer.g.dart"; | ||
|
||
/// so this just listens to navigation events and notifies the [NavigationController] to refresh its state | ||
/// we do not even use all of these callbacks, but they're for future-proofing | ||
class _NavigationObserver extends AutoRouterObserver { | ||
final Ref ref; | ||
|
||
_NavigationObserver(this.ref); | ||
|
||
void _notifyController() { | ||
ref.read(navigationControllerProvider.notifier).refreshState(); | ||
} | ||
|
||
@override | ||
void didPush(Route route, Route? previousRoute) { | ||
_notifyController(); | ||
super.didPush(route, previousRoute); | ||
} | ||
|
||
@override | ||
void didPop(Route route, Route? previousRoute) { | ||
_notifyController(); | ||
super.didPop(route, previousRoute); | ||
} | ||
|
||
@override | ||
void didRemove(Route route, Route? previousRoute) { | ||
_notifyController(); | ||
super.didRemove(route, previousRoute); | ||
} | ||
|
||
@override | ||
void didReplace({Route? newRoute, Route? oldRoute}) { | ||
_notifyController(); | ||
super.didReplace(newRoute: newRoute, oldRoute: oldRoute); | ||
} | ||
} | ||
|
||
@riverpod | ||
AutoRouterObserver navigationObserver(NavigationObserverRef ref) { | ||
return _NavigationObserver(ref); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import "package:auto_route/auto_route.dart"; | ||
|
||
class NoTransitionRoute extends CustomRoute { | ||
NoTransitionRoute({ | ||
required super.path, | ||
required super.page, | ||
}) : super( | ||
reverseDurationInMilliseconds: 0, | ||
durationInMilliseconds: 0, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters