route_observer_mixin
1.9.1, released 8 days ago by mono0926.com
Mixin and provider that expose RouteObserver callbacks like didPush and didPop for easy use.
What it does
It supplies a RouteObserverProvider and a RouteObserverMixin so widgets can listen to navigation events without boilerplate. The mixin forwards RouteAware callbacks and streams them via Provider/Riverpod.
AI-written summary of version 1.8.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to react to navigation events (push/pop) in a widget
- You already use Provider or Riverpod and want a lightweight solution
- You prefer a mixin rather than manual RouteObserver handling
Skip it when
- You need a full routing solution with deep linking or nested routes
- You rely on code‑generated route classes
- You don't use Provider/Riverpod and prefer a pure Navigator API
Strengths
- Very small and easy to add
- Works with both Provider and Riverpod
- Provides stream‑based access to route events
Weaknesses
- Only covers route‑observer callbacks, no routing features
- May clash if multiple RouteObservers are added
- Limited documentation beyond basic usage
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 4
Wrap MaterialApp with RouteObserverProvider (or use RouteObserverProvider widget) and add the mixin to your State class.
void main(){runApp(MultiProvider(providers:[RouteObserverProvider(),ChangeNotifierProvider(create:(_)=>Logger())],child:const App()));}
class App extends StatelessWidget{Widget build(BuildContext c){return MaterialApp(navigatorObservers:[RouteObserverProvider.of(c)],home:const APage());}}Alternatives
Packages that do the same job and could replace route_observer_mixin.
- auto_route
Provides full routing with generated routes and also supports route‑aware callbacks
87Compare - go_router
Offers declarative routing, deep linking and navigation guard features
98Compare
Works with
Packages commonly used together with route_observer_mixin: ones it builds on, ones built on it, and its own family.
- rxdartroute_observer_mixin depends on itImplementation of the ReactiveX API for asynchronous programming leveraging native Dart Streams.
- riverpodroute_observer_mixin depends on itA reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
- providerroute_observer_mixin depends on itA lightweight wrapper around InheritedWidget for state management
- disposable_providerroute_observer_mixin depends on itA thin wrapper around Provider that automatically calls dispose.
- firestore_refSame familyCross-platform Firestore type-safe reference and document wrapper.