Request constructor
Request({
- TransportPlatform? transportPlatform,
Implementation
factory Request({TransportPlatform? transportPlatform}) {
// If a transport platform is not explicitly given, fallback to the globally
// configured platform.
transportPlatform ??= globalTransportPlatform;
if (MockTransportsInternal.isInstalled) {
// If transports are mocked, return a mock-aware Request instance.
// This mock-aware instance will be able to decide at the time of dispatch
// whether or not the mock logic should handle the request.
return MockAwareTransportPlatform.newRequest(transportPlatform);
} else if (transportPlatform != null) {
// Otherwise, return a real instance using the given transport platform.
return transportPlatform.newRequest();
} else {
// If transports are not mocked and a transport platform is not available
// (neither explicitly given nor configured globally), then we cannot
// successfully construct a Request.
throw TransportPlatformMissing.httpRequestFailed('Request');
}
}