-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
Getting "XMLHttpRequest" error while using Chrome Web on VS Code #95532
Comments
I also want to know what address Flutter uses to launch it's application using Chrome web to set it as an Origin in backend side instead of using * wildcard? |
I changed the following line of the code: |
Hi @learner00000,
This is indeed the right solution for the web. The Android Emulator doesn't have a way to access localhost, which is why it was necessary for you to use
But calling that same URL won't work on web because that URL wouldn't actually be accessible. What you can do so that both URLs work for their respective platforms is to do something like final host = Platform.isAndroid ? '10.0.2.2' : '127.0.0.1';
final url = 'http://$host:8080/api/$urlSegment'; this way you ensure the right host is used for the right platform. Do note that the above is only for if you're testing with the android emulator. You could also host your backend and then just use that url. This is what I would recommend.
The app is always launched locally using localhost and a random port. You can set a port when you're launching it by running flutter run -d chrome --web-port=5000 Of course, the port could be anything you want it to be, so far as that port is available. |
Thank you very much for your help! (Although it doesn't recognize It was also another question for me to know how can I launch some different widgets/features respect to what platform does the user use? For example I want to either add a camera feature only when user launches the app using the smartphone or add a specific feature only users who use the web version can see and use that widget. I don't know what is the right manner doing that? Should I write separate widgets for mobile and web versions or I must add |
The
I will say it depends on the complexity of your designs and what exactly you're trying to achieve. There's a route you could go that will make it easier for you (you wouldn't need to specify a lot of conditionals), but that will involve writing more code. The other method is to check which platform you're running on and then enable that feature whether or not it is supposed to be there. If your UI isn't all that complex, you could get away with a few conditionals, but it becomes harder to maintain the more conditions you have to specify in your code. One way you could get away with this is to create a "wrapper" widget around the conditions you want. For example, you can create a Ultimately, I would say the concept of responsive design on the web can be applied in this context to achieve the desired effect. |
Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
When I launch my application on Chrome Web using VS Code and try to send a
http
request to the Backend side, it gives meXMLHttpRequest error
and does not work.When I launch the app on Android Emulator it works. Also I tried to add Allow-All-Origins and other CORS options in my Backend application but still I get the same error.
I also tried to deactivate CORS on Chrome Web but it also didn't work. I don't know if is it necessary to add what solutions I tried and didn't get the answer or not, but I also like to know if is it a Bug or a problem with Flutter or Chrome web?
The text was updated successfully, but these errors were encountered: