go_router_sugar library

go_router_sugar

Zero-effort file-based routing for Flutter with go_router.

Transform your Flutter routing from complex configuration to intuitive file organization. Your file system IS your route map - no boilerplate, no configuration, just works.

Core Philosophy: Zero Ambiguity

  • 🎯 Constructor Parameters = Route Parameters: No manual parameter extraction
  • πŸ“ File-Based Routing: Your file system becomes your route map
  • οΏ½ Smart Defaults: Works out of the box with intelligent conventions
  • πŸ›‘οΈ Type-Safe Navigation: Impossible to make navigation errors
  • ⚑ One-Command Setup: dart run go_router_sugar new my_app
  • πŸ”§ Progressive Enhancement: Simple start, powerful when needed

Quick Start

# Create complete app with routing ready
dart run go_router_sugar new my_app --template minimal
cd my_app && flutter run
// Constructor parameters become route parameters automatically
class ProductPage extends StatelessWidget {
  final String productId;    // βœ… Auto-injected from /products/:productId
  final String? category;    // βœ… Auto-injected from ?category=electronics

  const ProductPage({required this.productId, this.category});
}

// Type-safe navigation with perfect IntelliSense
Navigate.goToProduct(productId: '123', category: 'electronics');

Classes

Allow
Allows the navigation to proceed.
AnalyticsProvider
Analytics provider interface.
AppTemplate
A collection of PageTemplates to create a starter application.
AuthGuard
Simple auth guard implementation
Block
Blocks the navigation from proceeding.
ConsoleAnalyticsProvider
Built-in console analytics provider for debugging.
CustomParameterCodec
annotation to define a custom parameter decoder/encoder this is useful when the is encoded/decoded in a non-standard way like base64Url this must be used as an annotation on a field
CustomTransitionPage<T>
Page with custom transition functionality.
GoRoute Get started Configuration Redirection Transition animations Named routes
A route that is displayed visually above the matching parent route using the Navigator.
GoRouteData Type-safe routes
A class to represent a GoRoute in Type-safe routing.
GoRouteInformationParser
Converts between incoming URLs and a RouteMatchList using RouteMatcher.
GoRouteInformationProvider
The RouteInformationProvider created by go_router.
GoRouter Get started Upgrading Configuration Navigation Redirection Web Deep linking Named routes Error handling State restoration
The route configuration for the app.
GoRouterDelegate
GoRouter implementation of RouterDelegate.
GoRouterState
The route state during routing.
GoRouterSugarConfig
Default configuration constants for go_router_sugar.
ImperativeRouteMatch
The route match that represent route pushed through GoRouter.push.
InheritedGoRouter
GoRouter implementation of InheritedWidget.
InteractiveCLI
🎨 Beautiful Interactive CLI for Go Router Sugar
Navigation event data.
NoTransitionPage<T>
Custom transition page with no transition.
OnEnterResult
The result of an onEnter callback.
PageTemplate
A data class for a scaffolded page file.
PageTransition
Annotation to specify transition configuration for a page.
ParameterAnalysis
Analysis result containing detected parameters
ParameterDetector
Smart parameter detection for automatic route parameter injection
Protected
Annotation for protecting routes with guards
QueryParameter
Query parameter information
QueryParameterType
Annotation for specifying query parameter types for a route.
QueryParams
Base class for type-safe query parameter definitions.
RelativeGoRouteData Type-safe routes
A class to represent a relative GoRoute in Type-safe routing.
RoleGuard
Role-based permission guard
RouteAnalytics
Route analytics configuration.
RouteBase
The base class for GoRoute and ShellRoute.
RouteBuilder
Builds the top-level Navigator for GoRouter.
RouteConfiguration
The route configuration for GoRouter configured by the app.
RouteData
Baseclass for supporting Type-safe routing.
RouteGuard
Zero-config route guard system
RouteGuards
Multiple guards annotation
RouteInfo
Represents information about a route discovered during code generation.
RouteInformationState<T>
The data class to be stored in RouteInformation.state to be used by GoRouteInformationParser.
RouteMatch
An matched result by matching a GoRoute against a location.
RouteMatchBase
The base class for various route matches.
RouteMatchList
The list of RouteMatchBase objects.
RouteMiddlewares
Route middleware annotation for pages.
RouteParameter
Route parameter information
RoutePerformance
Performance monitoring for route transitions.
RoutingConfig Configuration
A set of parameters that defines routing in GoRouter.
ShellRoute Configuration
A route that displays a UI shell around the matching child route.
ShellRouteBase
Base class for classes that act as shells for sub-routes, such as ShellRoute and StatefulShellRoute.
ShellRouteContext
Context object used when building the shell and Navigator for a shell route.
ShellRouteData
A class to represent a ShellRoute in Type-safe routing.
ShellRouteMatch
An matched result by matching a ShellRoute against a location.
StatefulNavigationShell
Widget for managing the state of a StatefulShellRoute.
StatefulNavigationShellState
State for StatefulNavigationShell.
StatefulShellBranch
Representation of a separate branch in a stateful navigation tree, used to configure StatefulShellRoute.
StatefulShellBranchData
Base class for supporting StatefulShellRoute
StatefulShellRoute Configuration
A route that displays a UI shell with separate Navigators for its sub-routes.
StatefulShellRouteData
Base class for supporting StatefulShellRoute
TransitionConfig
Transition configuration for a route.
TypedGoRoute<T extends GoRouteData>
A superclass for each typed go route descendant
TypedRelativeGoRoute<T extends RelativeGoRouteData>
A superclass for each typed relative go route descendant
TypedRoute<T extends RouteData>
A superclass for each typed route descendant
TypedShellRoute<T extends ShellRouteData>
A superclass for each typed shell route descendant
TypedStatefulShellBranch<T extends StatefulShellBranchData>
A superclass for each typed shell route descendant
TypedStatefulShellRoute<T extends StatefulShellRouteData>
A superclass for each typed shell route descendant

Enums

The type of the navigation.
PageTransitionType
Available transition types for page navigation.

Extensions

GoRouterHelper on BuildContext
Dart extension to add navigation function to a BuildContext object, e.g. context.go('/');
GoRouterSugarExtensions on GoRouter
Extension methods to enhance GoRouter functionality
QueryParamNavigation on Type
Enhanced navigation helpers with query parameter support.

Constants

packageVersion β†’ const String
The current version of the go_router_sugar package.

Functions

logPageView(String route, Map<String, String> params) β†’ Future<void>
Example middleware function for logging page views.
trackAnalytics(String route, Map<String, String> params) β†’ Future<void>
Example middleware function for analytics tracking.

Typedefs

ExitCallback = FutureOr<bool> Function(BuildContext context, GoRouterState state)
Signature for function used in RouteBase.onExit.
GoExceptionHandler = void Function(BuildContext context, GoRouterState state, GoRouter router)
The function signature of GoRouter.onException.
GoRouterBuilderWithNav = Widget Function(BuildContext context, Widget child)
Signature of a go router builder function with navigator.
GoRouterPageBuilder = Page Function(BuildContext context, GoRouterState state)
The page builder for GoRoute.
GoRouterRedirect = FutureOr<String?> Function(BuildContext context, GoRouterState state)
The signature of the redirect callback.
GoRouterWidgetBuilder = Widget Function(BuildContext context, GoRouterState state)
The widget builder for GoRoute.
The function signature for navigation callbacks in _OnEnterHandler.
Signature for functions used to build Navigators
OnEnter = FutureOr<OnEnterResult> Function(BuildContext context, GoRouterState currentState, GoRouterState nextState, GoRouter goRouter)
The signature for the top-level onEnter callback.
OnEnterThenCallback = FutureOr<void> Function()
Signature for callbacks invoked after an OnEnterResult is resolved.
ParserExceptionHandler = RouteMatchList Function(BuildContext context, RouteMatchList routeMatchList)
The function signature of GoRouteInformationParser.onParserException.
PopPageWithRouteMatchCallback = bool Function(Route route, dynamic result, RouteMatchBase match)
Signature for a function that takes in a route to be popped with the result and returns a boolean decision on whether the pop is successful.
RouteInfoState = RouteInformationState
Type alias for route information state with dynamic type parameter.
RouteMatchVisitor = bool Function(RouteMatchBase)
The function signature for RouteMatchList.visitRouteMatches
ShellNavigationContainerBuilder = Widget Function(BuildContext context, StatefulNavigationShell navigationShell, List<Widget> children)
Builder for a custom container for the branch Navigators of a StatefulShellRoute.
ShellRouteBuilder = Widget Function(BuildContext context, GoRouterState state, Widget child)
The widget builder for ShellRoute.
ShellRoutePageBuilder = Page Function(BuildContext context, GoRouterState state, Widget child)
The page builder for ShellRoute.
StatefulShellRouteBuilder = Widget Function(BuildContext context, GoRouterState state, StatefulNavigationShell navigationShell)
The widget builder for StatefulShellRoute.
StatefulShellRoutePageBuilder = Page Function(BuildContext context, GoRouterState state, StatefulNavigationShell navigationShell)
The page builder for StatefulShellRoute.

Exceptions / Errors

GoError
Thrown when GoRouter is used incorrectly.
GoException
Thrown when GoRouter can not handle a user request.