No Context Navigation

No Context Navigation Package -

Instead of using Navigator.of(context).pushNamed or some other method like pop() or pushReplacementNamed() USING context. With this package you don't need to anymore.

This service use a GlobalKey of type NavigatorState which can be used across the entire applicaton.

Now, you only need to this:

navService.pushNamed('/detail_screen', args: 'From Home Screen');

But first, add the navigationKey to your MaterialApp's navigationKey property:

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      //Over here
      navigatorKey: NavigationService.navigationKey,
      onGenerateRoute: (RouteSettings settings) {
        switch ( {
          case '/':
            return MaterialPageRoute(builder: (context) => HomeScreen());
          case '/detail_screen':
            return MaterialPageRoute(
                builder: (context) =>
                    DetailScreen(message: settings.arguments));
            return null;

Use navService object to be able to acess those methods:

import 'package:flutter/material.dart';

final NavigationService navService = NavigationService();

class NavigationService<T, U> {
  static GlobalKey<NavigatorState> navigationKey = GlobalKey<NavigatorState>();

  Future<T> pushNamed(String routeName, {Object args}) async {
    return await navigationKey.currentState.pushNamed<T>(
      arguments: args,

  Future<T> push(Route<T> route) async {
    return await navigationKey.currentState.push<T>(route);

  Future<T> pushReplacementNamed(String routeName, {Object args}) async {
    return await navigationKey.currentState.pushReplacementNamed<T, U>(
      arguments: args,

  Future<T> pushNamedAndRemoveUntil(String routeName, {Object args}) async {
    return await navigationKey.currentState.pushNamedAndRemoveUntil<T>(
      (Route<dynamic> route) => false,
      arguments: args,

  Future<bool> maybePop([Object args]) async {
    return await navigationKey.currentState.maybePop<bool>(args);

  bool canPop() => navigationKey.currentState.canPop();

  bool goBack({Object result}) => navigationKey.currentState.pop<bool>(result);

Hope you enjoy!