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

Flutter Beta - Caught error: NoSuchMethodError: The method 'pushNamedAndRemoveUntil' was called on null #641

Closed
ghenry opened this issue Sep 23, 2020 · 20 comments
Assignees
Labels
invalid This doesn't seem right Waiting for customer response Without a valid reproduction code This issue does not contain a valid reproduction code and will be closed

Comments

@ghenry
Copy link

ghenry commented Sep 23, 2020

Describe the bug
On start up of my app, I get this error

[GETX] "AuthController" has been initialized
[GETX] "GetMaterialController" has been initialized
I/flutter ( 6822): Caught error: NoSuchMethodError: The method 'pushNamedAndRemoveUntil' was called on null.
I/flutter ( 6822): Receiver: null
I/flutter ( 6822): Tried calling: pushNamedAndRemoveUntil<dynamic>("/login", Closure: (Route<dynamic>) => bool, arguments: null)
I/flutter ( 6822): stackTrace: #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
I/flutter ( 6822): #1      GetNavigation.offAllNamed (package:get_navigation/src/extension_navigation.dart:262:36)
I/flutter ( 6822): #2      AuthController.checkLoggedIn (package:SureVoIPTalk/src/controller/auth.dart:72:11)
I/flutter ( 6822): #3      ever.<anonymous closure> (package:get_rx/src/rx_workers/rx_workers.dart:47:42)
I/flutter ( 6822): #4      _rootRunUnary (dart:async/zone.dart:1198:47)
I/flutter ( 6822): #5      _CustomZone.runUnary (dart:async/zone.dart:1100:19)
I/flutter ( 6822): #6      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
I/flutter ( 6822): #7      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
I/flutter ( 6822): #8      _DelayedData.perform (dart:async/stream_impl.dart:611:14)
I/flutter ( 6822): #9      _StreamImplEvents.handleNext (dart:async/stream_impl.dart:730:11)
I/flutter ( 6822): #10     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:687:7)
I/flutter ( 6822): #11     _rootRun (dart:async/zone.dart:1182:47)
I/flutter ( 6822): #12     _CustomZone.run (dart:async/zone.dart:1093:19)
I/flutter ( 6822): #13     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
I/flutter ( 6822): #14     _Custo
I/flutter ( 6822): In dev mode. Not sending report to Sentry.io.
[GETX] GOING TO ROUTE /login
[GETX] REMOVING ROUTE /

Expected behavior
No error

Flutter Version:
[✓] Flutter (Channel beta, 1.22.0-12.1.pre, on Linux, locale en_GB.UTF-8)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.49.0)
[✓] Connected device (4 available)

Getx Version:
3.11.1

Describe on which device you found the bug:
sdk gphone API 30

Minimal reproduce code

AuthController

  @override
  void onInit() {
    ever(isLoggedIn, checkLoggedIn);
    _loadLoggedIn();
    _loadUserDetails();
  }

  @override
  void onReady() {
    checkLoggedIn(null);
    super.onReady();
  }

  void checkLoggedIn(_) {
    if (isLoggedIn.value) {
      Get.offNamed("/home");
    } else {
      Get.offAllNamed("/login");
    }
  }

app.dart:

          home: SplashScreen(),
          getPages: [
            GetPage(
                name: "/home",
                page: () => HomeScreen(),
                binding: HomeBinding()),
            GetPage(name: "/login", page: () => LoginScreen()),
            GetPage(name: "/dialpad", page: () => DialpadScreen())
          ],
        ));
@fer-ri
Copy link
Contributor

fer-ri commented Sep 23, 2020

Where do you put AuthController? I can't see any reference to this controller on your reproduce code.

@ghenry
Copy link
Author

ghenry commented Sep 23, 2020

Hi @ghprod

This is in

class InitialBinding implements Bindings {
  @override
  void dependencies() {
    Get.put(UserRepository());
    Get.put(AuthController());
  }
}

but the InitialBinding was missed off my app.dart paste:

          initialBinding: InitialBinding(),
          home: SplashScreen(),
          getPages: [
            GetPage(
                name: "/home",
                page: () => HomeScreen(),
                binding: HomeBinding()),
            GetPage(name: "/login", page: () => LoginScreen()),
            GetPage(name: "/dialpad", page: () => DialpadScreen())
          ],
        ));

@fer-ri
Copy link
Contributor

fer-ri commented Sep 23, 2020

It works on my local. GetX 3.11.1, Flutter 1.20.4 • channel stable.

Next, please try to add a copy-pasting reproduce code.

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

main() => runApp(App());

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      home: HomeScreen(),
      initialBinding: BindingsBuilder(() {
        Get.put(AuthController());
      }),
      getPages: [
        GetPage(
          name: '/first',
          page: () => FirstScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<FirstController>(() => FirstController());
          }),
        ),
        GetPage(
          name: '/second',
          page: () => SecondScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<SecondController>(() => SecondController());
          }),
        ),
        GetPage(
          name: '/third',
          page: () => ThirdScreen(),
          binding: BindingsBuilder(() {
            Get.lazyPut<ThirdController>(() => ThirdController());
          }),
        ),
      ],
    );
  }
}

class AuthController extends GetxController {
  @override
  void onInit() {
    super.onInit();

    Future.delayed(Duration(seconds: 2), () => Get.offAllNamed('/third'));
  }
}

class FirstController extends GetxController {}

class SecondController extends GetxController {
  final title = 'Second'.obs;
}

class ThirdController extends GetxController {
  final title = 'Third'.obs;
}

class HomeScreen extends GetView<AuthController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text('Home'),
      ),
    );
  }
}

class FirstScreen extends GetView<FirstController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            RaisedButton(
              onPressed: () {
                Get.toNamed('/second?id=x');
              },
              child: Text('Go to Second'),
            ),
            RaisedButton(
              onPressed: () {
                Get.toNamed('/third?id=x');
              },
              child: Text('Go to Third'),
            ),
          ],
        ),
      ),
    );
  }
}

class SecondScreen extends GetView<SecondController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: () {
            Get.back();
          },
          child: Text('Back to First from ${controller.title.value}'),
        ),
      ),
    );
  }
}

class ThirdScreen extends GetView<ThirdController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: () {
            Get.offNamed('/first');
          },
          child: Text('Off to First ${controller.title.value}'),
        ),
      ),
    );
  }
}
[GETX] "AuthController" has been initialized
[GETX] "GetMaterialController" has been initialized
I/mple.getx_debu(23042): ProcessProfilingInfo new_methods=532 is saved saved_to_disk=1 resolve_classes_delay=8000
[GETX] GOING TO ROUTE /third
[GETX] REMOVING ROUTE /
[GETX] Lazy instance "ThirdController" created
[GETX] "ThirdController" has been initialized

@ghenry
Copy link
Author

ghenry commented Sep 23, 2020 via email

@fer-ri
Copy link
Contributor

fer-ri commented Sep 23, 2020

I c.. sorry my local just use Stable channel.

@ghenry
Copy link
Author

ghenry commented Sep 23, 2020

I c.. sorry my local just use Stable channel.

Thanks for your time and effort though. Greatly appreciated. I'll update the subject.

@ghenry ghenry changed the title Caught error: NoSuchMethodError: The method 'pushNamedAndRemoveUntil' was called on null. Flutter Beta - Caught error: NoSuchMethodError: The method 'pushNamedAndRemoveUntil' was called on null Sep 23, 2020
@fer-ri
Copy link
Contributor

fer-ri commented Sep 23, 2020

No problems hopes you can find solution too 👍

@ghenry
Copy link
Author

ghenry commented Sep 23, 2020 via email

@jonataslaw
Copy link
Owner

Using the Dev branch is working for me.
I will switch to branch beta to make sure it works well, but it seems more like a cache error, or something, than a problem.
I will try to confirm this soon.

@Prn-Ice
Copy link

Prn-Ice commented Sep 25, 2020

I have this issue on Channel beta, 1.21.0-9.2.pre, but only during tests.

NoSuchMethodError: The method 'pushNamed' was called on null.
Receiver: null
Tried calling: pushNamed<dynamic>("/login", arguments: null)
dart:core                                                                              Object.noSuchMethod
package:get/src/navigation/extension_navigation.dart 103:36                            GetNavigation.toNamed
package:bells_dash/modules/splash/presentation/controller/splash_controller.dart 68:9  SplashController._navigateToLogin
package:bells_dash/modules/splash/presentation/controller/splash_controller.dart 44:9  SplashController.navigateUser
test/modules/splash/presentation/controller/splash_controller_test.dart 107:20         main.<fn>.<fn>.<fn>

@ghenry
Copy link
Author

ghenry commented Oct 1, 2020

Just testing 3.12.1 and latest beta

@ghenry
Copy link
Author

ghenry commented Oct 1, 2020

Yeah, still same for me:

I/flutter ( 5313): Caught error: NoSuchMethodError: The method 'pushNamedAndRemoveUntil' was called on null.
I/flutter ( 5313): Receiver: null
I/flutter ( 5313): Tried calling: pushNamedAndRemoveUntil<dynamic>("/login", Closure: (Route<dynamic>) => bool, arguments: null)
I/flutter ( 5313): stackTrace: #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
I/flutter ( 5313): #1      GetNavigation.offAllNamed (package:get_navigation/src/extension_navigation.dart:262:36)
I/flutter ( 5313): #2      AuthController.checkLoggedIn (package:SureVoIPTalk/src/controller/auth.dart:72:11)
I/flutter ( 5313): #3      ever.<anonymous closure> (package:get_rx/src/rx_workers/rx_workers.dart:47:42)


[✓] Flutter (Channel beta, 1.22.0-12.3.pre, on Linux, locale en_GB.UTF-8)

@jonataslaw
Copy link
Owner

Just one question, is this during testing?
Because if it is, using the latest version you can use
Get.TestMode = true.
If it's in the normal build, I can't reproduce

@ghenry
Copy link
Author

ghenry commented Oct 10, 2020 via email

@Nipodemos
Copy link
Collaborator

Nipodemos commented Oct 10, 2020

Could you send us a reproducible code that I can paste in my computer and replicate the issue?

Tried right now that portion of code you pasted here and it worked properly, so the issue is not in there.

Flutter (Channel beta, 1.22.1, on Microsoft Windows [versão 10.0.18363.1082], locale pt-BR)
Get: 3.13.2

@Nipodemos Nipodemos added the Without a valid reproduction code This issue does not contain a valid reproduction code and will be closed label Oct 10, 2020
@ghenry
Copy link
Author

ghenry commented Oct 10, 2020 via email

@ghenry
Copy link
Author

ghenry commented Oct 12, 2020

Not seeing this now when upgrading from 3.12.1 to 3.13.2:

[GETX] "AuthController" has been initialized
[GETX] "GetMaterialController" has been initialized
[GETX] GOING TO ROUTE /login
[GETX] REMOVING ROUTE /

versus:

[GETX] "AuthController" has been initialized
[GETX] "GetMaterialController" has been initialized
I/flutter ( 6822): Caught error: NoSuchMethodError: The method 'pushNamedAndRemoveUntil' was called on null.
I/flutter ( 6822): Receiver: null
I/flutter ( 6822): Tried calling: pushNamedAndRemoveUntil<dynamic>("/login", Closure: (Route<dynamic>) => bool, arguments: null)
I/flutter ( 6822): stackTrace: #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
I/flutter ( 6822): #1      GetNavigation.offAllNamed (package:get_navigation/src/extension_navigation.dart:262:36)
I/flutter ( 6822): #2      AuthController.checkLoggedIn (package:SureVoIPTalk/src/controller/auth.dart:72:11)
I/flutter ( 6822): #3      ever.<anonymous closure> (package:get_rx/src/rx_workers/rx_workers.dart:47:42)
I/flutter ( 6822): #4      _rootRunUnary (dart:async/zone.dart:1198:47)
I/flutter ( 6822): #5      _CustomZone.runUnary (dart:async/zone.dart:1100:19)
I/flutter ( 6822): #6      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
I/flutter ( 6822): #7      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
I/flutter ( 6822): #8      _DelayedData.perform (dart:async/stream_impl.dart:611:14)
I/flutter ( 6822): #9      _StreamImplEvents.handleNext (dart:async/stream_impl.dart:730:11)
I/flutter ( 6822): #10     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:687:7)
I/flutter ( 6822): #11     _rootRun (dart:async/zone.dart:1182:47)
I/flutter ( 6822): #12     _CustomZone.run (dart:async/zone.dart:1093:19)
I/flutter ( 6822): #13     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
I/flutter ( 6822): #14     _Custo
I/flutter ( 6822): In dev mode. Not sending report to Sentry.io.
[GETX] GOING TO ROUTE /login
[GETX] REMOVING ROUTE /

I think we're good now. Any ideas what it was?

@jonataslaw
Copy link
Owner

Probably cache.
There was no change from one version to another, however I realized that when you run a build and make many changes without using a "flutter clean", the Flutter cache ends up getting in the way and causing errors such as:
pushAnything was called null.
Bad stream events cannot be added to a closed stream.

When you have errors of the type, type flutter clean in the IDE's terminal, close and open the project, and compile again.
If everything is ok for you, I will close this issue

@ghenry
Copy link
Author

ghenry commented Oct 12, 2020 via email

@jonataslaw
Copy link
Owner

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right Waiting for customer response Without a valid reproduction code This issue does not contain a valid reproduction code and will be closed
Projects
None yet
Development

No branches or pull requests

6 participants