flutter_navigator

A Flutter package for simplified page-to-page navigation using a custom method (NavigatorHelper.to(pageName)).

Features

  • Simple Navigation: Navigate between pages using a straightforward method.
  • Centralized Route Management: Manage routes and configurations in one place.
  • Typed Navigation: Support typed navigation for type safety.
  • Middleware Support: Intercept and modify navigation behavior with middleware functions.

Usage

-Import the package import 'package:flutter_navigator/flutter_navigator.dart';

-Define Routes class AppRoutes { static const home = '/home'; static const profile = '/profile'; static const settings = '/settings'; }

-Initialize NavigatorHelper void main() { NavigatorHelper.init({ AppRoutes.home: (context) => HomePage(), AppRoutes.profile: (context) => ProfilePage(), AppRoutes.settings: (context) => SettingsPage(), });

runApp(MyApp()); }

-Navigate Between Pages NavigatorHelper.to(AppRoutes.profile);

-Middleware Example class AuthMiddleware { static void checkLoggedIn(Function next) { if (isLoggedIn) { next(); } else { NavigatorHelper.to(AppRoutes.home); } } }

// Usage: NavigatorHelper.to(AppRoutes.profile, middleware: AuthMiddleware.checkLoggedIn);

Installation

Add flutter_navigator to your pubspec.yaml file:

dependencies:
  flutter_navigator: ^1.0.0 # Replace with the latest version