Don’t use ‘BuildContext’s across async gaps. (Documentation) Try rewriting the code to not reference the ‘BuildContext’.

Solution

Add if(context.mounted) before the Navigator related code. But basically, you should not do route redirect in general classes. You should put these UI related code in your Stateful or Stateless pages. Don’t mix UI with your business logic.