Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter web http.get return "Unsupported operation: Platform._version"

Tags:

flutter

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.
like image 248
user12800095 Avatar asked Jan 28 '20 15:01

user12800095


2 Answers

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.

like image 140
Richard Avatar answered Nov 14 '22 11:11

Richard


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 if dart:io is available and a BrowserClient if dart:html is available, otherwise it will throw an unsupported error.

like image 1
wamfous Avatar answered Nov 14 '22 13:11

wamfous