getCurrentNavigatorRouteName static method

String? getCurrentNavigatorRouteName(
  1. BuildContext context
)

Trick explained here: https://github.com/flutter/flutter/issues/20451 Note 'ModalRoute.of(context).settings.name' doesn't always work.

Implementation

static String? getCurrentNavigatorRouteName(BuildContext context) {
  late Route currentRoute;
  Navigator.popUntil(context, (route) {
    currentRoute = route;
    return true;
  });
  return currentRoute.settings.name;
}