Page class
Marks a class as a page that will be registered with the Spark router.
Pages are the entry points for your application's routes. Each page class must extend SparkPage and will be automatically registered with the generated router.
Usage
@Page(path: '/users/:id')
class UserPage extends SparkPage<User> {
@override
Future<PageResponse<User>> loader(PageRequest request) async {
final userId = request.pathParamInt('id');
final user = await fetchUser(userId);
if (user == null) return PageRedirect('/404');
return PageData(user);
}
@override
String render(User data, PageRequest request) {
return '<h1>${data.name}</h1>';
}
}
Path Parameters
Use :paramName syntax for path parameters:
/users/:id- Single parameter/posts/:postId/comments/:commentId- Multiple parameters
Parameters are available via PageRequest.pathParams.
Constructors
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited