Add progress tracking capabilities to the API request system, allowing users to monitor the progress of HTTP requests, especially useful for file uploads, downloads, and long-running operations.
/// Function type for handling request progress updates
typedef ProgressHandler = void Function(ProgressData progress);
/// Data class containing progress information
class ProgressData {
final int sentBytes;
final int totalBytes;
final double percentage;
final ProgressType type;
const ProgressData({
required this.sentBytes,
required this.totalBytes,
required this.percentage,
required this.type,
});
}
enum ProgressType {
upload,
download,
}- Add
ProgressHandler? onProgresscallback property - Add
withProgress(ProgressHandler handler)method for fluent API - Integrate progress callbacks with Dio's
onSendProgressandonReceiveProgress
- Update HTTP methods (get, post, put, delete) to support progress callbacks
- Pass progress handlers to Dio's Options configuration
- Handle both upload and download progress tracking
- ✅ Create
ProgressDataclass andProgressHandlertypedef - ✅ Add progress callback properties to
RequestActionbase class - ✅ Implement fluent API methods (
withProgress,withUploadProgress,withDownloadProgress)
Phase 1 Status: COMPLETED
- Created
/src/progress/progress_data.dartwithProgressDataclass andProgressTypeenum - Created
/src/progress/progress_handler.dartwith progress handler typedefs - Added progress callback properties to
RequestActionbase class - Implemented fluent API methods with comprehensive documentation
- Updated main export file to include progress functionality
- All code compiles successfully with no errors
- ✅ Modify
RequestClientto accept progress callbacks - ✅ Update all HTTP method implementations (get, post, put, delete)
- ✅ Wire progress callbacks to Dio's native progress tracking
Phase 2 Status: COMPLETED
- Added progress callback helper methods to
RequestActionbase class - Updated GET method with
onReceiveProgresscallback support - Updated POST method with both
onSendProgressandonReceiveProgresscallback support - Updated PUT method with both
onSendProgressandonReceiveProgresscallback support - DELETE method documented as not supporting progress (Dio limitation)
- Added
_hasProgressHandlersgetter to optimize callback registration - Added
_onSendProgressand_onReceiveProgressmethods to convert Dio callbacks toProgressData - Integrated with existing
_handleProgressmethod for handler propagation - All HTTP methods now support progress tracking where Dio allows it
- Code compiles successfully with no errors
- ✅ Integrate progress callbacks with existing lifecycle hooks
- ✅ Ensure progress callbacks work with both
execute()andonQueue()methods - ✅ Add progress support to streaming operations
Phase 3 Status: COMPLETED
- Progress callbacks are automatically integrated with both
execute()andonQueue()methods - No additional lifecycle code needed - progress works through existing HTTP method calls
- Added example implementations in
post_service.dartshowing three patterns:createPostWithProgress(): Direct execution with progress callbackscreatePostStream(): Streaming execution with progress callbacks- Both upload and download progress tracking supported
- Progress callbacks work seamlessly with existing error handling and success callbacks
- Stream-based operations maintain progress tracking throughout the request lifecycle
- All tests pass and code compiles successfully
- ✅ Add progress tracking to
SimpleApiRequestutility class - ✅ Create specialized progress actions for file operations
- ✅ Add progress reporting to performance monitoring system
Phase 4 Status: COMPLETED
- Enhanced
SimpleApiRequestwith fluent progress tracking API (withProgress,withUploadProgress,withDownloadProgress) - Integrated automatic progress callbacks with all HTTP methods (GET, POST, PUT, download)
- Updated existing
FileDownloadActionto support unified progress system with backward compatibility - Created new
FileUploadActionwith comprehensive file upload support, multi-file handling, and progress tracking - Enhanced
PerformanceReportclass with upload/download byte tracking, transfer rate calculations, and improved formatting - Integrated progress data collection into
ApiRequestPerformancemonitoring system - Added automatic performance tracking for all progress-enabled requests
- All new features maintain backward compatibility and follow existing architectural patterns
- Progress tracking now works seamlessly across all request types (actions, simple requests, file operations)
Phase 4 Completed Successfully - All enhanced features implemented and integrated with existing systems.
final result = await CreatePostAction(request)
.withProgress((progress) {
print('Upload progress: ${progress.percentage}%');
updateProgressBar(progress.percentage);
})
.execute();final result = await FileUploadAction(file)
.withUploadProgress((progress) {
print('Uploading: ${progress.percentage}%');
})
.withDownloadProgress((progress) {
print('Processing: ${progress.percentage}%');
})
.execute();action
.withProgress((progress) => progressController.add(progress))
.subscribe(
onSuccess: (data) => handleSuccess(data),
onError: (error) => handleError(error),
)
.onQueue();lib/src/
├── actions/
│ ├── api_request_action.dart # Add progress support
│ ├── request_action.dart # Core progress implementation
│ └── file_download_action.dart # Enhanced with progress
├── progress/ # New directory
│ ├── progress_data.dart # Progress data structures
│ └── progress_handler.dart # Progress callback types
├── api_request_client.dart # Update HTTP methods
└── simple_api_request.dart # Add progress methods
- All progress features are optional (callbacks default to null)
- Existing API remains unchanged
- No breaking changes to current functionality
- Progressive enhancement approach
- Unit tests for progress data calculations
- Integration tests with mock HTTP requests
- Tests for both upload and download scenarios
- Performance impact testing
- Stream-based progress testing
- Update README with progress tracking examples
- Add progress-specific dartdoc comments
- Create migration guide for adding progress to existing actions
- Example implementations for common use cases
- High Priority: Core progress infrastructure and basic callback support
- Medium Priority: Full HTTP client integration and lifecycle hooks
- Low Priority: Enhanced features and specialized actions
- Zero breaking changes to existing API
- Progress callbacks work with all HTTP methods
- Both upload and download progress supported
- Integration with existing error handling and lifecycle
- Comprehensive test coverage
- Clear documentation and examples