'Flutter: Move to a new screen without using navigate

do you have any way to open new screen without using navigation, i want when i open a new screen, the fist stop and play continuous when i go back from the second screen,

i want when i open many creen like the image below, the D creen have a button the button will go back to the A creen, not open new tab A creen

I dont't want it like this:

enter image description here

I want this:

enter image description here



Solution 1:[1]

Navigator.of(context).pushAndRemoveUntil(
      MaterialPageRoute(
        builder: (BuildContext context) => A(),
      ),
      (Route route) => false,
    );

Above line help you to achieve your requirement.

Replace A() With your destination class.

Solution 2:[2]

There can be 2 ways to this:

  1. You can use Navigator.popUntil since you have to go back to the first screen. This can only be used in case you know how many screens you want to pop.
count = 0;
Navigator.popUntil(context, (route) {
    return count++ == 2;
});
  1. You can also use Navigator.pushReplacementNamed route. Check the link for more reference https://api.flutter.dev/flutter/widgets/Navigator/pushReplacementNamed.html
Navigator.pushReplacementNamed(context, folder/A)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ujjwal Raijada