Flutter: Exception using Navigator.of(context).pop();

256

Nevermind, found the problem.

Basically, when going from one page to another, I've always called "Navigator.of(context).push(new MaterialPageRoute)" passing also a callback function (if necessary). When that callback function is not passed (null) the error is thrown.

Thanks anyway to anyone who replied!

Share:
256
Gianni Ottimista
Author by

Gianni Ottimista

Updated on December 25, 2022

Comments

  • Gianni Ottimista
    Gianni Ottimista over 1 year

    Every time I use Navigator.of(context).pop(); to return to the previous view I always get the

    Unhandled Exception: NoSuchMethodError: The method 'call' was called on null.

    message.

    However, the app successfully goes back to the previous view, but I don't know why I always get this message that sometimes causes a crash. What could it be?

    #0      _rootRunUnary (dart:async/zone.dart:1198:47)
    #1      _CustomZone.runUnary (dart:async/zone.dart:1100:19)
    #2      _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
    #3      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
    #4      Future._propagateToListeners (dart:async/future_impl.dart:725:32)
    #5      Future._completeWithValue (dart:async/future_impl.dart:529:5)
    #6      Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
    #7      _rootRun (dart:async/zone.dart:1190:13)
    #8      _CustomZone.run (dart:async/zone.dart:1093:19)
    #9      _CustomZone.runGuarded (dart:async/zone.dart:997:7)
    #10     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
    #11     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
    #12     _startMicrotaskLoop<…>
    

    I usually use an Inkwell associated with an icon to call the method. In example:

    InkWell(onTap: () => Navigator.of(context).pop(), 
    
      child: Icon(Icons.chevron_left_rounded, color: Constants.COLOR_DEF, size: 30));
    
    • Akif
      Akif over 3 years
      Please provide some code related to your call method.
    • Gianni Ottimista
      Gianni Ottimista over 3 years
      Oh yes, I forgot.
  • Gianni Ottimista
    Gianni Ottimista over 3 years
    Yes I do, because even with this error the app goes back to the previous page. However, when I go from one page to another I always push a new MaterialPageRoute: Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => dest, settings: RouteSettings(name: "/" + routeName))).then(callbackFunction);
  • Akshit Ostwal
    Akshit Ostwal over 3 years
    ok than I would need some more code related to this problem, if you can provide that would be great or else I would be blind shooting 😅