render method
Overrides the render method from the Render interface.
This method sets the HTTP status code and the Location header for the response. Throws an Exception if the status code is not a valid redirect status code.
Implementation
@override
void render(Response response) {
// Check if the status code is a valid redirect status code (3xx) or 201 (Created).
if ((code < HttpStatus.multipleChoices ||
code > HttpStatus.permanentRedirect) &&
code != HttpStatus.created) {
throw Exception('Cannot redirect with status code $code');
}
// Set the status code and Location header in the response.
response.statusCode = code;
response.headers.set(HttpHeaders.locationHeader, location);
}