This error happened when opening a bottomsheet for me. I added this check to it and it fixed it:
if (!context.mounted || ModalRoute.of(context)?.isCurrent != true) return;