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

Response<double> get error when got int #691

Closed
a43mrk opened this issue Mar 3, 2020 · 3 comments
Closed

Response<double> get error when got int #691

a43mrk opened this issue Mar 3, 2020 · 3 comments

Comments

@a43mrk
Copy link

a43mrk commented Mar 3, 2020

Hello i got an error that Dio cannot cast integer numbers to double, in this end-point its supposed to return only float numbers. but he returns to integers :( this code was generated by retrofit and the author said to post here, because he don't want to make any changes on the generator.
The error occurs the respose is assigned.

New Issue Checklist

  • [x ] I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name e.g. flutter / ios / android all
Platform Version e.g. 1.5.0 / 12.0 / 9.0 13.0
Dio Version e.g. 2.1.0 / 1.0.17 3.x
Android Studio / Xcode Version e.g. Android Studio 3.3.2 / Xcode 10.2.1 Xcode 11
Repro rate e.g. all the time (100%) / sometimes x% / only once 100%
Repro with our demo prj e.g. does it happen with our demo project? x
Demo project link e.g. link to a demo project that highlights the issue x
 getFooBarById(id) async {
   ArgumentError.checkNotNull(id, 'id');
   const _extra = <String, dynamic>{};
   final queryParameters = <String, dynamic>{};
   final _data = <String, dynamic>{};
   final Response<double> _result = await _dio.request('/foo/barById/$id',
       queryParameters: queryParameters,
       options: RequestOptions(
           method: 'GET',
           headers: <String, dynamic>{},
           extra: _extra,
           baseUrl: baseUrl),
       data: _data);
   final value = _result.data;
   return Future.value(value);
 }

Exception has occurred.
DioError (DioError [DioErrorType.DEFAULT]: type 'int' is not a subtype of type 'double'
#0 DioMixin.assureResponse (package:dio/src/dio.dart:1138:9)
#1 DioMixin._request. (package:dio/src/dio.dart:904:14)
#2 _rootRunUnary (dart:async/zone.dart:1134:38)
#3 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#4 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
#5 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
#6 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
#7 Future._complete (dart:async/future_impl.dart:514:7)
#8 _SyncCompleter.complete (dart:async/future_impl.dart:53:12)
#9 Future.any. (dart:async/future.dart:459:45)
#10 _rootRunUnary (dart:async/zone.dart:1134:38)
#11 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#12 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
#13 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
#14 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
#15 Future._completeWithValue (dart:async/future_impl.dart:524:5)
#16 Future._asyncComplete. (dart:async/future_impl.dart:554:7)
#17 _rootRun (dart:async/zone.dart:1126:13)
#18 _CustomZone.run (dart:async/zone.dart:1023:19)
#19 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#20 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:965:23)
#21 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#22 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)

@stale
Copy link

stale bot commented Apr 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Apr 2, 2020
@stale stale bot closed this as completed Apr 9, 2020
@a43mrk
Copy link
Author

a43mrk commented Jul 8, 2020

hellow! is Dio alive?

@josephcrowell
Copy link

I just changed my code based on the http library to dio. Under http, doubles with a precision of 0 like 153.000000 were correctly created as a double type per the dart standard, but in dio, any whole number double is instead converted to an integer. This violates the way doubles are supposed to work in Flutter/Dart and your json parser needs to be fixed to handle whole number doubles correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants