SchabanBo / qlevar_router

Manage you project Routes. Create nested routes. Simply navigation without context to your pages. Change only one sub widget in your page when navigating to new route.
MIT License
86 stars 22 forks source link

qlevar is popping all non-qlevar routes #132

Closed Zazo032 closed 1 year ago

Zazo032 commented 1 year ago

We're currently migrating our current codebase from older Navigator.push/pop to ´qlevar`. Our app currently has 4 main routes, let's call them A, B, C and D, which can only be navigated in order: A->B->C->D.

Only routes A and B are migrated to qlevar, and from B to D we're still navigating using Navigator.push/pop. At this point, I found 2 issues which I'm not sure if are related:

@SchabanBo do you have any idea of what could be happening here?

Zazo032 commented 1 year ago

Code to reproduce the issue:

```dart import 'package:flutter/material.dart'; import 'package:qlevar_router/qlevar_router.dart'; void main() { runApp(const DemoApp()); } class DemoApp extends StatefulWidget { const DemoApp({Key? key}) : super(key: key); @override State createState() => _DemoAppState(); } class _DemoAppState extends State { @override void initState() { super.initState(); qrSetup(); } void qrSetup() { QR.settings.autoRestoration = true; QR.settings.oneRouteInstancePerStack = true; QR.setUrlStrategy(); } final routes = [ QRoute( path: '/', builder: () => const RouteA(), ), QRoute( path: '/b', builder: () => const RouteB(), ), ]; @override Widget build(BuildContext context) { return MaterialApp.router( routeInformationParser: const QRouteInformationParser(), routerDelegate: QRouterDelegate(routes), restorationScopeId: 'app', ); } } class RouteA extends StatelessWidget { const RouteA({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('A'), ), body: Center( child: OutlinedButton( child: const Text('B'), onPressed: () { QR.to('/b'); }, ), ), ); } } class RouteB extends StatelessWidget { const RouteB({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('B'), ), body: Center( child: OutlinedButton( child: const Text('C'), onPressed: () { Navigator.of(context).push( MaterialPageRoute( builder: (_) => const RouteC(), ), ); }, ), ), ); } } class RouteC extends StatelessWidget { const RouteC({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('C'), ), body: const Center( child: FlutterLogo(), ), ); } } ```
  1. Tap B to go to B route
  2. Tap C to go to C route
  3. Go back with native Android back button/gesture or tap hot reload
SchabanBo commented 1 year ago

@Zazo032 it's important to use a consistent navigation system throughout your app. Mixing different navigation systems can lead to conflicts and unexpected behavior. It is not good practice to use more than one navigator in the app. In this way, the package will not be able to communicate with the extra navigator 1 you add separately. So you will need to migrate all your routes to use qlevar to solve this issue.