Skip to content
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

Improve usage example and tests #1933

Merged
merged 6 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dio/lib/src/dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ abstract class Dio {
/// ),
/// onReceiveProgress: (received, total) {
/// if (total != -1) {
/// print((received / total * 100).toStringAsFixed(0) + '%');
/// print('${(received / total * 100).toStringAsFixed(0)}%');
/// }
/// },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// onReceiveProgress: (received, total) {
/// if (total != -1) {
/// print((received / total * 100).toStringAsFixed(0) + '%');
/// print('${(received / total * 100).toStringAsFixed(0)}%');
/// }
/// },
/// onReceiveProgress: (received, total) {
/// if(total < 1) return;
/// final percentage = (received / total * 100).toStringAsFixed(0)
/// print('$percentage%');
/// },

/// );
Expand Down
4 changes: 2 additions & 2 deletions example/lib/download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ Future download2(Dio dio, String url, String savePath) async {
}
}

void showDownloadProgress(received, total) {
void showDownloadProgress(int received, int total) {
if (total != -1) {
print((received / total * 100).toStringAsFixed(0) + '%');
print('${(received / total * 100).toStringAsFixed(0)}%');
}
Copy link
Contributor

@ueman ueman Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (total != -1) {
print((received / total * 100).toStringAsFixed(0) + '%');
print('${(received / total * 100).toStringAsFixed(0)}%');
}
if (total < 1) return;
final percentage = (received / total * 100).toStringAsFixed(0)
print('$percentage%');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I replaced 1 with 0 because 0 is the actual boundary value.
  • I merged the definition and the print statement together.
-  if (total < 1) return;
-  final percentage = (received / total * 100).toStringAsFixed(0)
-  print('$percentage%');
+  if (total <= 0) return;
+  print('percentage: ${(received / total * 100).toStringAsFixed(0)}%');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced 1 with 0 because 0 is the actual boundary value.

That's fine for me.

I merged the definition and the print statement together.

I believe that's harder to read, but since no one else complained, it seems like that's a me problem :D

}
8 changes: 0 additions & 8 deletions example/lib/formdata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import 'dart:io';
import 'package:dio/dio.dart';
import 'package:dio/io.dart';

void showProgress(received, total) {
if (total != -1) {
print((received / total * 100).toStringAsFixed(0) + '%');
}
}

Future<FormData> formData1() async {
return FormData.fromMap({
'name': 'wendux',
Expand Down Expand Up @@ -92,7 +86,6 @@ void main() async {
final dio = Dio();
dio.options.baseUrl = 'http://localhost:3000/';
dio.interceptors.add(LogInterceptor());
// dio.interceptors.add(LogInterceptor(requestBody: true));
dio.httpClientAdapter = IOHttpClientAdapter(
createHttpClient: () {
final client = HttpClient();
Expand All @@ -116,7 +109,6 @@ void main() async {
print(utf8.decode(await data3.readAsBytes()));

response = await dio.post(
//"/upload",
'http://localhost:3000/upload',
data: data3,
onSendProgress: (received, total) {
Expand Down