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

Flutter web app freezes when http get request is made #400

Closed
Mateis opened this issue Apr 2, 2020 · 4 comments
Closed

Flutter web app freezes when http get request is made #400

Mateis opened this issue Apr 2, 2020 · 4 comments

Comments

@Mateis
Copy link

Mateis commented Apr 2, 2020

I would like to fetch information from an API using an HTTP GET request to a public endpoint which returns XML, in Flutter (web).

However, when I run the code in debug mode, and I reach the screen where the API HTTP request is made, app freezes.

I wrote the following code:

import 'dart:async';

import 'package:http/http.dart' as http;
import 'package:xml/xml.dart' as xml;

class SearchApi {

Future fetchPhotos(String query) async {
  final http.Response response = await http.get('https://www.gahetna.nl/beeldbank-api/opensearch/?searchTerms=auto&startIndex=1&count=10', headers: {"Accept": "application/xml"});

  print(response.body);

  if (response.statusCode == 200) {
    // If the server did return a 200 OK response,
    // then parse the XML.
    print(xml.parse(response.body));

    return xml.parse(response.body);
  } else {
    // If the server did not return a 200 OK response,
    // then throw an exception.
    throw Exception('Failed to load photos');
  }
}

The code works when I change the http.get url to for instance 'https://jsonplaceholder.typicode.com/todos/1'. The http get request works to the 'https://www.gahetna.nl/beeldbank-api/opensearch/' endpoint, when I use curl in command line.

There are no error messages shown in Visual Studio Code IDE when the screen freezes.

@lanistor
Copy link

lanistor commented Apr 9, 2020

My Flutter App has the same problem, it will last more than 3 seconds. And i'm using
Http: v0.12.0+2, Dart: 2.8.0, Flutter 1.15.3

@natebosch
Copy link
Member

Is there an error in the browser console?

Does this reproduce if you use dart:html directly?

@Mateis
Copy link
Author

Mateis commented Apr 20, 2020

@natebosch I appreciate your reply! I wish I replied sooner. My Github notification was set to a dead emailaddress.

I cannot show the error in the browser console at the moment. In the meanwhile, I ran into another issue: flutter/flutter#54040. This issue leads to me being unable to run the app in the browser at all.

@Mateis
Copy link
Author

Mateis commented Apr 21, 2020

It works. This may have been part of the issue: flutter/flutter#41336

Yet I believe it also may have to do with an CORS error (which I also fixed by using a proxy).

@Mateis Mateis closed this as completed Apr 21, 2020
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

3 participants