I'm developing flutter web app and trying to get some data from the internet I'm using package:http/http.dart And trying to do this:
await http.get(url);
but I got this error:
Unsupported operation: Platform._version
daz@daz:/rom/source/public/checkout_example$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.16.2-pre.41, on Linux, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 3.6)
[!] IntelliJ IDEA Community Edition (version 2019.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (3 available)
! Doctor found issues in 2 categories.
I'm sure you have figured this out by now but I just had the same problem and came across this post.
So, having now worked out the solution, I figured I would post it here to save the next person who comes across it some time.
The solution is to update the version of the http
plugin in pubspec.yaml
I had been using http: "0.11.3+17"
and getting that error.
I updated the entry in pubspec.yaml
to http: ^0.12.1
and it works.
The problem I had was I was explicitly using an IOClient
, which isn't supported on the browser; a BrowserClient
needs to be used in this case (this is using http v0.13.3
).
The solution:
var client = http.Client();
creates the right one depending on the platform.
From the Client()
docs:
Creates an
IOClient
ifdart:io
is available and aBrowserClient
ifdart:html
is available, otherwise it will throw an unsupported error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With