GithubHelp home page GithubHelp logo

Comments (5)

herna avatar herna commented on June 18, 2024

Ok after further testing, I can see it's related to a Dialog.

I have a button to display a Dialog like this:

showDialog<bool>(
                context: context,
                builder: (BuildContext context) => AlertDialog(
                actions: <Widget>[
                  FilledButton(
                    onPressed: () async {
                      await context.popRoute();
                      // this is a Riverpod call to delete an item from the database
                      ref
                          .read(installationEditControllerProvider(
                                  widget.installationId)
                              .notifier)
                          .deleteInstallation(widget.installationId);
                    }),
                  child: Text('Delete'),
                ],
              ),
);

And in another part of the widget I detect the Riverpod response after the item is deleted to redirect to another page. At this point, if I just do a context.navigateTo(const InstallationsRoute()); it doesn't work but if I do a small pause like the following, then it works:

Future.delayed(const Duration(milliseconds: 200), () => context.navigateTo(const InstallationsRoute()));
It seems related to the time it takes to close the Dialog. The problem is even if I wait like this await context.popRoute(); it doesn't work, I must put a small delay anyway.

Future<void> doInstallationDeleted(BuildContext context) async {
    await Future(() async {
      // IT WORKS
      // Future.delayed(const Duration(milliseconds: 200),
      //     () => context.navigateTo(const InstallationsRoute()));

      // IT DOESN'T WORK
      // context.navigateTo(const InstallationsRoute());
    });
  }

What's the correct way to deal with showDialog() and auto_route?

Thanks.

from auto_route_library.

tomlezen avatar tomlezen commented on June 18, 2024

I also found this issue; this is because navigateTo is asynchronous !

from auto_route_library.

herna avatar herna commented on June 18, 2024

Hi @tomlezen

So how to deal with it? I realised that and tried to await context.navigateTo(const InstallationsRoute()); but nothing changes

Thanks.

from auto_route_library.

tomlezen avatar tomlezen commented on June 18, 2024

Hi @tomlezen

So how to deal with it? I realised that and tried to await context.navigateTo(const InstallationsRoute()); but nothing changes

Thanks.

You can try to use:context.popForced

from auto_route_library.

herna avatar herna commented on June 18, 2024

Thanks @tomlezen

This seems to work for the Dialog. Anyways I am also facing some other issues when combining navigateTo() with didPopNext(), I was trying to just invalidate a Riverpod provider in the didPopNext() method to refresh some data but it's not always working the same way so I have to manually call ref.invalidate() before navigateTo() to ensure it works as expected.

Thanks again.

from auto_route_library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.