tp_router_generator 0.6.2 copy "tp_router_generator: ^0.6.2" to clipboard
tp_router_generator: ^0.6.2 copied to clipboard

discontinuedreplaced by: teleport_router_generator

A build_runner code generator that processes tp_router annotations to generate type-safe routing code for Flutter applications.

tp_router_generator #

pub package

Code generator for tp_router - A Flutter package that provides type-safe, annotation-based routing built on top of go_router.

Overview #

tp_router_generator processes @TpRoute, @TpShellRoute, and @TpStatefulShellRoute annotations to automatically generate type-safe routing code. It eliminates boilerplate and ensures compile-time safety for your navigation logic.

Installation #

Add to your dev_dependencies in pubspec.yaml:

dependencies:
  tp_router: any

dev_dependencies:
  build_runner: any
 tp_router_generator: any

Usage #

1. Annotate Your Pages #

import 'package:tp_router_annotation/tp_router_annotation.dart';

@TpRoute()
class HomePage extends StatelessWidget {
  const HomePage({super.key});
  // ... widget implementation
}

2. Run Code Generation #

# One-time generation
flutter pub run build_runner build

# Watch mode (auto-regenerate on changes)
flutter pub run build_runner watch

# Delete conflicting outputs and rebuild
flutter pub run build_runner build --delete-conflicting-outputs

3. Use Generated Routes #

After generation, you'll get type-safe route classes:

// Navigate using generated route
HomeRoute().tp(context);

// With parameters
UserRoute(userId: '123').tp(context);

Generated Code #

The generator creates:

  • Type-safe route classes: One for each @TpRoute annotated page
  • Parameter extraction: Automatic handling of path, query, and extra parameters
  • Route configuration: TpRouteInfo objects for go_router integration
  • Global route list: tpRoutes containing all routes in your app
  • Static fromData method: Reconstruct typed route instances from generic data objects
  • Class-based Callbacks: Support for TpRedirect and TpOnExit implementations

Configuration #

Customize the output file location in build.yaml:

targets:
  $default:
    builders:
      tp_router_generator:
        options:
          output: lib/generated/routes.g.dart

Features #

  • ✅ Generates type-safe route classes (e.g., HomeRoute, UserRoute)
  • ✅ Handles parameter extraction from path, query, and extra data
  • ✅ Supports custom transitions and global configuration
  • ✅ Supports shell routes (TpShellRoute, TpStatefulShellRoute)
  • ✅ Compile-time validation of route parameters
  • ✅ Static reconstruction via fromData method
  • ✅ Class-based redirection and lifecycle guards
  • ✅ Automatic path generation from class names

Example #

See the tp_router example for a complete working application demonstrating all features.

License #

See the main tp_router repository for license information.

0
likes
40
points
369
downloads

Publisher

unverified uploader

Weekly Downloads

A build_runner code generator that processes tp_router annotations to generate type-safe routing code for Flutter applications.

License

MIT (license)

Dependencies

analyzer, build, glob, source_gen, tp_router_annotation

More

Packages that depend on tp_router_generator