-
Notifications
You must be signed in to change notification settings - Fork 31
feat: add multipart upload support to DioService with progress tracking #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
71216cc
914d471
f9b157a
894c298
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import 'dart:typed_data'; | ||
| import 'package:dio/dio.dart'; | ||
| import 'package:http_parser/http_parser.dart'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Verify that generated Flutter pubspec templates declare http_parser directly.
set -eu
printf 'Import sites:\n'
rg -n -C2 "package:http_parser/http_parser.dart" --iglob '*.hbs' --iglob '*.dart' || true
printf '\nDirect dependency declarations expected under dependencies:\n'
rg -n -C3 "^[[:space:]]*http_parser:" --iglob 'pubspec*.hbs' --iglob 'pubspec.yaml' || trueRepository: Arjun544/flutter_init Length of output: 720 Add Line 3 imports 🤖 Prompt for AI Agents |
||
|
|
||
| class UploadFilePayload { | ||
| final String? filePath; | ||
| final Uint8List? bytes; | ||
| final String fieldName; | ||
| final String? fileName; | ||
| final String? mimeType; | ||
|
|
||
| const UploadFilePayload._({ | ||
| this.filePath, | ||
| this.bytes, | ||
| required this.fieldName, | ||
| this.fileName, | ||
| this.mimeType, | ||
| }); | ||
|
|
||
| factory UploadFilePayload({ | ||
| String? filePath, | ||
| Uint8List? bytes, | ||
| String fieldName = 'file', | ||
| String? fileName, | ||
| String? mimeType, | ||
| }) { | ||
| if (filePath == null && bytes == null) { | ||
| throw ArgumentError('UploadFilePayload requires either filePath or bytes.'); | ||
| } | ||
| return UploadFilePayload._( | ||
| filePath: filePath, | ||
| bytes: bytes, | ||
| fieldName: fieldName, | ||
| fileName: fileName, | ||
| mimeType: mimeType, | ||
| ); | ||
| } | ||
|
|
||
| String get _resolvedFileName => | ||
| fileName ?? | ||
| (filePath != null | ||
| ? filePath!.split(RegExp(r'[/\\]')).last | ||
| : 'upload'); | ||
|
|
||
| MediaType? get _mediaType => | ||
| mimeType != null ? MediaType.parse(mimeType!) : null; | ||
|
|
||
| Future<MultipartFile> toMultipartFile() async { | ||
| if (bytes != null) { | ||
| return MultipartFile.fromBytes( | ||
| bytes!, | ||
| filename: _resolvedFileName, | ||
| contentType: _mediaType, | ||
| ); | ||
| } | ||
| return MultipartFile.fromFile( | ||
| filePath!, | ||
| filename: _resolvedFileName, | ||
| contentType: _mediaType, | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| class UploadProgress { | ||
| final int sent; | ||
| final int total; | ||
|
|
||
| const UploadProgress({required this.sent, required this.total}); | ||
|
|
||
| /// 0.0–1.0. Returns 0.0 when [total] is unknown (server omits Content-Length). | ||
| double get percentage => | ||
| total > 0 ? (sent / total).clamp(0.0, 1.0) : 0.0; | ||
|
|
||
| /// True when the server did not return Content-Length. | ||
| bool get isIndeterminate => total <= 0; | ||
|
|
||
| @override | ||
| String toString() => | ||
| 'UploadProgress(sent: $sent, total: $total, ' | ||
| '${(percentage * 100).toStringAsFixed(1)}%)'; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.