gt_navigation 1.0.0 copy "gt_navigation: ^1.0.0" to clipboard
gt_navigation: ^1.0.0 copied to clipboard

A production-ready Flutter navigation package with middleware, deep linking, nested navigation, custom transitions, and type-safe routing.

gt_navigation #

pub package License: MIT

A production-ready Flutter navigation package with middleware, deep linking, nested navigation, custom transitions, and type-safe routing.

✨ Features #

Feature Description
🧭 Context-Free Navigation Navigate from anywhere using AppRouter() singleton
πŸ›‘οΈ Middleware Guards Auth checks and route protection with automatic redirects
πŸ”— Deep Linking Handle deep links and notification routes seamlessly
πŸ“± Nested Navigation Independent stacks for tabs and multi-pane layouts
🎨 Custom Transitions 7 built-in types: fade, slide, scale, rotation, cupertino, material, none
🎯 Dynamic Routes Regex-based path matching (e.g., /user/:id/posts/:postId)
πŸ“Š Route Observers Track navigation for analytics and debugging

πŸ“¦ Installation #

Add to your pubspec.yaml:

dependencies:
  gt_navigation: ^1.0.0

πŸš€ Quick Start #

1. Define Routes #

// route_constants.dart
class Routes {
  static const String home = '/home';
  static const String login = '/login';
  static const String userProfile = '/user/:id';
  static const String settings = '/settings';
}

2. Create Route Configurations #

// app_pages.dart
class AppPages {
  static final List<AppRoute> all = [
    AppRoute(
      path: Routes.home,
      builder: (context, args) => const HomeScreen(),
      transition: const AppTransition(type: AppTransitionType.fade),
    ),
    AppRoute(
      path: Routes.userProfile,
      builder: (context, args) => UserProfileScreen(args: args),
      transition: const AppTransition(
        type: AppTransitionType.slide,
        direction: AppTransitionDirection.bottomToTop,
      ),
    ),
    AppRoute(
      path: Routes.settings,
      builder: (context, args) => const SettingsScreen(),
      middlewares: [AuthGuardMiddleware()], // Protected route
    ),
  ];
}

3. Initialize in main.dart #

void main() {
  AppRouter().initialize(
    routes: AppPages.all,
    deepLinkConfig: const DeepLinkConfig(
      scheme: 'myapp',
      host: 'example.com',
    ),
    enableLogging: true,
  );
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: AppRouter().navigatorKey,
      onGenerateRoute: AppRouter().onGenerateRoute,
      navigatorObservers: [AppRouter().routeObserver],
      initialRoute: Routes.home,
    );
  }
}

4. Navigate! #

// Basic navigation
AppRouter().navigateTo(Routes.home);

// With path parameters
AppRouter().navigateTo('/user/123');

// With arguments
AppRouter().navigateTo(
  '/user/456',
  arguments: AppRouteArguments(
    queryParameters: {'tab': 'posts'},
    data: {'isAdmin': true},
  ),
);

// Replace current screen
AppRouter().navigateTo(
  Routes.home,
  mode: NavigationModes.pushReplacement,
);

// Clear stack (e.g., logout)
AppRouter().navigateTo(
  Routes.login,
  mode: NavigationModes.pushAndRemoveAll,
);

// Go back
AppRouter().goBack();

πŸ›‘οΈ Middleware Example #

class AuthGuardMiddleware extends AppMiddleware {
  @override
  Future<bool> canNavigate(
    BuildContext context,
    String route,
    AppRouteArguments? args,
  ) async {
    return await AuthService.isLoggedIn();
  }

  @override
  String? getRedirectRoute() => Routes.login;
}

πŸ“– Documentation #

For detailed documentation on all features including:

  • Deep link setup for iOS/Android
  • Nested navigation patterns
  • Custom transitions
  • State restoration
  • Testing strategies

See the example folder and API documentation.

πŸ“„ License #

MIT License - see LICENSE for details.

0
likes
150
points
142
downloads

Publisher

unverified uploader

Weekly Downloads

A production-ready Flutter navigation package with middleware, deep linking, nested navigation, custom transitions, and type-safe routing.

Repository (GitHub)
View/report issues

Topics

#navigation #router #routing #deep-linking #middleware

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on gt_navigation