The http_interceptor library is designed to work seamlessly across all Flutter platforms. This document outlines the supported platforms and provides guidance on platform-specific considerations.
- Android: Full support for all HTTP methods, request types, and interceptors
- iOS: Full support for all HTTP methods, request types, and interceptors
- Flutter Web: Full support for all HTTP methods, request types, and interceptors
- Windows: Full support for all HTTP methods, request types, and interceptors
- macOS: Full support for all HTTP methods, request types, and interceptors
- Linux: Full support for all HTTP methods, request types, and interceptors
All standard HTTP methods are supported across all platforms:
GET- Retrieve dataPOST- Create or submit dataPUT- Update dataDELETE- Remove dataPATCH- Partial updatesHEAD- Get headers only
All request types work consistently across platforms:
- Basic Requests:
Requestobjects with headers, body, and query parameters - Streamed Requests:
StreamedRequestfor large data or real-time streaming - Multipart Requests:
MultipartRequestfor file uploads and form data
All response types are supported:
- Basic Responses:
Responseobjects with status codes, headers, and body - Streamed Responses:
StreamedResponsefor large data or streaming responses
Interceptors work identically across all platforms:
- Request Interception: Modify requests before they're sent
- Response Interception: Modify responses after they're received
- Conditional Interception: Choose when to intercept based on request/response properties
- Multiple Interceptors: Chain multiple interceptors together
When using the library on Flutter Web:
- CORS: Be aware of Cross-Origin Resource Sharing policies
- Network Security: HTTPS is recommended for production
- Browser Limitations: Some advanced networking features may be limited
When using the library on mobile platforms:
- Network Permissions: Ensure proper network permissions in your app
- Background Processing: Consider network requests during app lifecycle
- Platform-Specific Headers: Some headers may behave differently
When using the library on desktop platforms:
- System Integration: Network requests integrate with system proxy settings
- Performance: Generally better performance for large requests/responses
- Security: Follow platform-specific security guidelines
The library includes comprehensive platform support tests that verify:
- ✅ HTTP method support across all platforms
- ✅ Request type handling (Basic, Streamed, Multipart)
- ✅ Response type handling (Basic, Streamed)
- ✅ Interceptor functionality
- ✅ Error handling and edge cases
- ✅ Platform detection and identification
- ✅ Cross-platform data type handling
- ✅ Client lifecycle management
- ✅ Multiple client instance handling
- 24 platform-specific tests covering all major functionality
- 258 total tests ensuring comprehensive coverage
- 100% pass rate across all supported platforms
import 'package:http_interceptor/http_interceptor.dart';
// Create interceptors
final loggerInterceptor = LoggerInterceptor();
final authInterceptor = AuthInterceptor();
// Build client with interceptors
final client = InterceptedClient.build(
interceptors: [loggerInterceptor, authInterceptor],
);
// Use the client (works on all platforms)
final response = await client.get(Uri.parse('https://api.example.com/data'));class PlatformAwareInterceptor implements InterceptorContract {
@override
Future<BaseRequest> interceptRequest({required BaseRequest request}) async {
// Add platform-specific headers
final modifiedRequest = request.copyWith();
if (kIsWeb) {
modifiedRequest.headers['X-Platform'] = 'web';
} else if (Platform.isAndroid) {
modifiedRequest.headers['X-Platform'] = 'android';
} else if (Platform.isIOS) {
modifiedRequest.headers['X-Platform'] = 'ios';
}
return modifiedRequest;
}
@override
BaseResponse interceptResponse({required BaseResponse response}) => response;
}// Works on Android, iOS, Web, and Desktop
final multipartRequest = MultipartRequest('POST', Uri.parse('https://api.example.com/upload'));
// Add form fields
multipartRequest.fields['description'] = 'My file upload';
// Add files (works on all platforms)
final file = MultipartFile.fromString(
'file',
'file content',
filename: 'document.txt',
);
multipartRequest.files.add(file);
final response = await client.send(multipartRequest);// Use HTTPS for production web apps
final client = InterceptedClient.build(
interceptors: [webSecurityInterceptor],
);
// Handle CORS appropriately
class WebSecurityInterceptor implements InterceptorContract {
@override
Future<BaseRequest> interceptRequest({required BaseRequest request}) async {
final modifiedRequest = request.copyWith();
modifiedRequest.headers['Origin'] = 'https://yourdomain.com';
return modifiedRequest;
}
}// Handle network state changes
class MobileNetworkInterceptor implements InterceptorContract {
@override
Future<BaseRequest> interceptRequest({required BaseRequest request}) async {
// Add mobile-specific headers
final modifiedRequest = request.copyWith();
modifiedRequest.headers['User-Agent'] = 'MyApp/1.0 (Mobile)';
return modifiedRequest;
}
}// Leverage desktop performance for large files
class DesktopOptimizationInterceptor implements InterceptorContract {
@override
Future<BaseRequest> interceptRequest({required BaseRequest request}) async {
// Optimize for desktop performance
final modifiedRequest = request.copyWith();
modifiedRequest.headers['X-Desktop-Optimized'] = 'true';
return modifiedRequest;
}
}-
Web CORS Errors
- Ensure your server allows requests from your domain
- Use appropriate CORS headers in your interceptors
-
Mobile Network Issues
- Check network permissions in your app manifest
- Handle network state changes appropriately
-
Desktop Proxy Issues
- Configure system proxy settings if needed
- Test with different network configurations
import 'package:flutter/foundation.dart';
import 'dart:io';
String getPlatformName() {
if (kIsWeb) return 'web';
if (Platform.isAndroid) return 'android';
if (Platform.isIOS) return 'ios';
if (Platform.isWindows) return 'windows';
if (Platform.isMacOS) return 'macos';
if (Platform.isLinux) return 'linux';
return 'unknown';
}The http_interceptor library provides comprehensive support for all Flutter platforms with consistent behavior and full feature parity. The extensive test suite ensures reliability across all supported platforms, making it a robust choice for cross-platform Flutter applications.
For more information about specific platform features or troubleshooting, refer to the main documentation or create an issue on the GitHub repository.