Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when assigning arguments during consecutive navigations #978

Open
DimensaSpaki opened this issue Nov 22, 2024 · 0 comments
Open

Error when assigning arguments during consecutive navigations #978

DimensaSpaki opened this issue Nov 22, 2024 · 0 comments
Labels
new New issue request attention

Comments

@DimensaSpaki
Copy link

Describe the bug
In the case of multiple consecutive navigations, calling Modular.to.pushNamed followed by another, the arguments from the last navigation is used for all the others.
If the argument of the last navigation is null, null is used along.

To Reproduce

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

void main() {
  runApp(ModularApp(module: AppModule(), child: const AppWidget()));
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerDelegate: Modular.routerDelegate,
      routeInformationParser: Modular.routeInformationParser,
    );
  }
}

class AppModule extends Module {
  @override
  void routes(r) {
    r.child('/', child: (_) => const HomePage());
    r.child('/first', child: (_) => Page(title: r.args.data));
    r.child('/second', child: (_) => Page(title: r.args.data));
    r.child('/third', child: (_) => Page(title: r.args.data));
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home')),
      body: Center(
        child: ElevatedButton(
          onPressed: navigateThroughPages,
          child: const Text('Navigate'),
        ),
      ),
    );
  }

  void navigateThroughPages() {
    Modular.to.pushNamed('/first', arguments: 'First Page');
    Modular.to.pushNamed('/second', arguments: 'Second Page');
    Modular.to.pushNamed('/third', arguments: 'Third Page');
  }
}

class Page extends StatelessWidget {
  const Page({super.key, required this.title});

  final String title;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(title)),
      body: Center(
        child: ElevatedButton(
          onPressed: Modular.to.pop,
          child: const Text('Pop'),
        ),
      ),
    );
  }
}

Expected behavior
It was expected that each navigation would use the arguments provided to it.

Screenshots
Observe the route and compare it with the text in the app bar, which is passed as Modular.pushNamed arguments.

image
image
image
image

The screenshots are from a web application just to make it easier to visualize the route, but this also occurs on other platforms.

I tested the same logic with go_router and got the expected behavior.

image
image
image

@DimensaSpaki DimensaSpaki added the new New issue request attention label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new New issue request attention
Projects
None yet
Development

No branches or pull requests

1 participant