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
87 stars 22 forks source link

Wrong path selection #125

Closed gabriel-gheorghe closed 3 months ago

gabriel-gheorghe commented 1 year ago

Consider the following scenario:

QRoute(
      path: '/schedule',
      name: schedule,
      builder: () => const ScheduleView(),
    ),
QRoute(
      path: '/scheduleDetailed',
      name: scheduleDetailed,
      builder: () => const ScheduleDetailedView(),
    ),

First time you switch your view to "schedule", it shows the "ScheduleView", correct. Second time you switch to "schedule", it shows the "ScheduleDetailedView", wrong.

My temporary fix: I replaced '/scheduleDetailed' path with '/detailed' and now '/schedule' path works fine everytime I switch to it.

SchabanBo commented 3 months ago

Could not reproduce the Problem, This work works as expected

import 'package:flutter/material.dart';
import 'package:qlevar_router/qlevar_router.dart';

void main() async {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    final List<QRoute> router = [
      QRoute(
        path: '/',
        builder: () {
          return const HomePage();
        },
      ),
      QRoute(
        path: '/schedule',
        name: 'schedule',
        builder: () => const PageOne(),
      ),
      QRoute(
        path: '/scheduleDetailed',
        name: 'scheduleDetailed',
        builder: () => const PageTow(),
      ),
    ];
    return MaterialApp.router(
      routeInformationParser: const QRouteInformationParser(),
      routerDelegate: QRouterDelegate(router, withWebBar: true),
    );
  }
}

const navigatorName = 'bottom sheet';

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.green,
      body: Center(
        child: Column(
          children: [
            ElevatedButton(
              child: const Text("Go"),
              onPressed: () async {
                QR.to('/schedule');
              },
            ),
          ],
        ),
      ),
    );
  }
}

class PageOne extends StatefulWidget {
  const PageOne({super.key});

  @override
  State<PageOne> createState() => _PageOneState();
}

class _PageOneState extends State<PageOne> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Page One"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            TextButton(
              child: const Text("Go to page 2"),
              onPressed: () {
                QR.to('/scheduleDetailed');
              },
            ),
            TextButton(
              child: const Text("Back"),
              onPressed: () {
                QR.back();
              },
            ),
          ],
        ),
      ),
    );
  }
}

class PageTow extends StatelessWidget {
  const PageTow({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Page One"),
      ),
      body: const Center(
        child: Icon(Icons.home),
      ),
    );
  }
}