flutter_route_manager 0.0.1 copy "flutter_route_manager: ^0.0.1" to clipboard
flutter_route_manager: ^0.0.1 copied to clipboard

A simple Flutter package for managing navigation.

flutter_route_manager #

A lightweight and static navigation utility for Flutter that simplifies route management using a global NavigatorState. Navigate from anywhere in your app — even outside widget trees — without passing BuildContext.


✨ Features #

  • Navigate to pages without BuildContext
  • Push, replace, or pop routes from anywhere
  • Centralized navigation logic
  • Works with both MaterialApp and CupertinoApp

🚀 Installation #

Add the following to your pubspec.yaml:

dependencies:
    flutter_route_manager:
        git:
            url: https://github.com/ahmedelmwafy/flutter_route_manager.git

Or, if published on pub.dev:

flutter pub add flutter_route_manager

🧠 Usage #

1. Assign the global key to your app #

import 'package:flutter/material.dart';
import 'package:flutter_route_manager/flutter_route_manager.dart';

void main() {
    runApp(MyApp());
}

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            navigatorKey: navigatorKey, // Assign the global key
            onGenerateRoute: onGenerateRoute, // Optional
            home: HomeScreen(),
        );
    }
}

2. Navigate between pages #

You can now navigate from anywhere in your code, even outside widget trees:

import 'package:flutter_route_manager/flutter_route_manager.dart';

// Push a new screen
RouteManager.navigateTo(SecondScreen());

// Push and remove all previous routes
RouteManager.navigateAndPopAll(LoginScreen());

// Push and pop until the first route
RouteManager.navigateAndPopUntilFirstPage(SettingsScreen());

// Pop the current route (optionally with a result)
RouteManager.pop(); // or RouteManager.pop(result);

🧩 API Reference #

Method Description
navigateTo(Widget page) Push a new screen on top of the current one.
navigateAndPopAll(Widget page) Push and remove all previous routes.
navigateAndPopUntilFirstPage(Widget) Push and pop until the first route.
pop([Object? result]) Pop the current route, optionally with result.
currentContext Returns the current BuildContext.

📦 Integration Tips #

  • Ideal for apps using clean architecture, BLoC, or services outside the widget tree that need to trigger navigation.
  • Can be used together with named routes via onGenerateRoute.

🛠️ Contributing #

Contributions, issues, and feature requests are welcome!
Feel free to open a PR or submit an issue.

10
likes
130
points
24
downloads

Publisher

unverified uploader

Weekly Downloads

A simple Flutter package for managing navigation.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_route_manager