2
votes

I have a project that worked fine but after latest flutter core update it doesn't,I got:

E/flutter ( 4510): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3582 pos 12: '_history.any(_RouteEntry.isPresentPredicate)': Navigator has no active routes to replace. E/flutter ( 4510): #0
_AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39) E/flutter ( 4510): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)

  Future<void> _submit() async {
    if (!_formKey.currentState.validate()) {
      return;
    }
    _formKey.currentState.save();

    final pref = await SharedPreferences.getInstance();
    pref.setString('ip', _ip);
    pref.setBool('isTablet', isTablet);
   pref.setBool('setting1', isActivated);

     
// error on next part of the code

      Navigator.of(context).pop(); 
      Navigator.of(context).pushReplacementNamed('/');

      Provider.of<Auth>(context, listen: false).logout();
  }

thanks

1

1 Answers

5
votes

Based on your problem, I'm assuming that you have 2 routes. 1 for the current screen that contains your submit function and then the other 1 is the '/'.

Navigator.of(context).pop(); // closes the current screen
Navigator.of(context).pushReplacementNamed('/') // replaces the current screen

So if you do pop the current screen, the next line on your code with gave an error because there is no route on the stack in which your snippet will replace. Remove the Navigator.of(context).pop(); it will solve your problem.