Giter Site home page Giter Site logo

Comments (7)

jlubeck avatar jlubeck commented on July 16, 2024 1

Wow, I was trying to go back (like you said) to a non-existant route. BUT, not because it got removed, I was just using a different name for it.

Sorry for wasting your time...

from getx.

jonataslaw avatar jonataslaw commented on July 16, 2024

Get.until could not bring any error in the snackbar, and if it does, placing the snackbar in the front can solve it (in some cases the animation of the snackbar can last longer than the animation of the route, and can cause problems, so I recommend inserting the snackbar always after the route in any case).
But I just can't reproduce your example. Everything works fine for me with your code.

void main() {
  runApp(MaterialApp(
    initialRoute: "/",
    navigatorKey: Get.key,
    onGenerateRoute: Router.generateRoute,
    navigatorObservers: [
      GetObserver(),
    ],
  ));
}

class Router {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case '/':
        return GetRoute(
          page: First(),
          settings: settings,
        );
      case '/second':
        return GetRoute(settings: settings, page: Second());
      case '/third':
        return GetRoute(
            settings: settings,
            page: Third(),
            popGesture: true,
            transition: Transition.cupertino);
      default:
        return GetRoute(
            settings: settings,
            transition: Transition.fade,
            page: Scaffold(
              body:
                  Center(child: Text('No route defined for ${settings.name}')),
            ));
    }
  }
}

class First extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: Icon(Icons.add),
          onPressed: () {
            Get.snackbar("hi", "i am a modern snackbar");
          },
        ),
        title: Text('First Route counter'),
      ),
      body: Center(
        child: RaisedButton(
          color: Colors.blue,
          child: Text('Open route'),
          onPressed: () {
            Get.toNamed("/second");
          },
        ),
      ),
    );
  }
}

class Second extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: Icon(Icons.add),
          onPressed: () {
            Get.snackbar("hi", "i am a modern snackbar");
          },
        ),
        title: Text('second Route'),
      ),
      body: Center(
        child: RaisedButton(
          color: Colors.blue,
          child: Text('Open route'),
          onPressed: () {
            Get.offNamed("/third");
          },
        ),
      ),
    );
  }
}

class Third extends StatefulWidget {
  @override
  _ThirdState createState() => _ThirdState();
}

class _ThirdState extends State<Third> {
  bool isCreatingPatient = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Third Route"),
      ),
      body: Center(
        child: RaisedButton(
          color: Colors.blue,
          onPressed: () {
           //  Get.close(2); // you can to use it
            Get.snackbar(
              'Patient ',
              'Successfully added',
              colorText: Colors.white,
            );
            Get.until('/', (Route route) {
              setState(() {
                isCreatingPatient =
                    false; // It does not make sense to change the state of a screen that will be closed, I think that this may be unnecessary.
              }); //
              return route.settings.name == '/';
            });
          },
          child: Text('Go back!'),
        ),
      ),
    );
  }
}

It may be good to remember that there is Get.close(2); which does exactly the same thing as you did with Get.until, more clearly, perhaps.
In addition, although I am sure that this is not a problem with Get, I have the slight impression that you may have taken the first route you want to return to from the tree, if that happens, you will experience an error.
Navigator.popUntil/Get.until are sensitive to initialRoute, mixing named routes with common routes can cause errors; Try to see if your code in the MaterialApp has an initialRoute property or if you are not removing the route you want to return to.

from getx.

jlubeck avatar jlubeck commented on July 16, 2024

I can't use Get.close(2) because this same widget gets used in different scenarios, sometimes when there is 1 screen inbetween, but also when there are 2. That's why I was using Get.until.

The first route is definitely not removed.

My MaterialApp does have an initialRoute though. Which is where I want the app to start. How does that get handled with onGenerateRoute ?

from getx.

jlubeck avatar jlubeck commented on July 16, 2024

Although your example also has initialRoute, so that doesn't sound like the problem...

from getx.

jonataslaw avatar jonataslaw commented on July 16, 2024

Although your example also has initialRoute, so that doesn't sound like the problem...

Look for something that is using index in your code. In every lib, I don't use index on anything, and this error may be related to a widget that has lost its status in some way.
If the problem occurs in the web version, there is currently an issue related to onGenerateRoute returning null and missing the initial route.

from getx.

jonataslaw avatar jonataslaw commented on July 16, 2024

Which line of code is the error appearing on?

from getx.

jlubeck avatar jlubeck commented on July 16, 2024

Well, good news for you is that I can't replicate the problem on a new project.
Bad news for me is that I can't fix it on mine haha

Going to keep trying to do either and will get back to you

from getx.

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.