How to remove all routes from the Navigator in Flutter

Remove all routes from the Navigator stack in Flutter, useful for implementing logout functionality.

Helpful for designing functionality of a Logout button

Navigator.of(context).pushNamedAndRemoveUntil(
    '/desiredNamedRoute',
    (Route<dynamic> route) => false,
  );