handle method Null safety
- Request request
override
The primary request handling method of this object.
Subclasses implement this method to provide their request handling logic.
If this method returns a Response, it will be sent as the response for request
linked controllers will not handle it.
If this method returns request
, the linked controller handles the request.
If this method returns null, request
is not passed to any other controller and is not responded to. You must respond to request
through Request.raw.
Implementation
@override
FutureOr<RequestOrResponse?> handle(Request request) async {
this.request = request;
final preprocessedResult = await willProcessRequest(request);
if (preprocessedResult is Request) {
return _process();
} else if (preprocessedResult is Response) {
return preprocessedResult;
}
throw StateError(
"'$runtimeType' returned invalid object from 'willProcessRequest'. Must return 'Request' or 'Response'.",
);
}