Route class
A comprehensive route management and request processing system for web applications. The Route class serves as the core routing engine that processes incoming HTTP requests, matches them against defined route patterns, and handles the appropriate response rendering. It supports features like nested routing, URL parameters, authentication, permission checks, static file serving, and widget rendering. Key features:
- Pattern-based route matching with URL parameters (
{id},{name}, etc.) - Nested route structures with parent-child relationships
- Host and port-based routing restrictions
- Authentication and authorization integration
- Static file serving from public directory
- Widget and controller-based response handling
- Automatic MIME type detection for static files Example usage:
final routes = [
WebRoute(
path: '/api/users/{id}',
methods: [RequestMethods.GET],
index: () async => handleUserRequest(),
),
];
final router = Route(routing: routes);
router.handle(); // Process the current request
Constructors
-
Route({required List<
FinchRoute> routing}) - Creates a Route instance.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
routing
↔ List<
FinchRoute> -
A list of FinchRoute objects defining the routing paths and configurations.
getter/setter pair
- rq → Request
-
The Request object representing the current web request.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- seenAuth ↔ AuthController?
-
An optional AuthController instance used for managing authentication.
getter/setter pair
Methods
-
checkAll(
List< FinchRoute> routing, {String parentPath = ''}) → Future<bool> - Checks all routes to determine if a request matches any defined route.
-
checkOne(
FinchRoute route, String key) → Future< ({bool found, Map< String, Object?> urlParams})> - Checks a single route to see if it matches the given key.
-
checkPermission(
AuthController? auth) → Future< bool> - Checks if the current request has the required permissions.
-
getFileFromPublic(
String path) → File - Retrieves a file from the public directory based on the provided path.
-
getParamsPath(
String clientPath, String serverPath) → (String, Map< String, Object?> ) - Extracts URL parameters from route patterns and matches them with request paths.
-
getPublicDirectory(
String? filePath) → String - Constructs the full path to a file in the public directory.
-
handle(
) → void - Initiates the route processing workflow for the current request.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
renderFile(
File file) → void - Renders a file by streaming its content to the response.
-
renderWidget(
String uri) → void - Renders a widget-based view for the current request.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited