I have been stuck on this lesson for a few hours trying to troubleshoot. I continue to get a "Something went wrong" message. I made the update to Uri so it's not that. I have restarted Android Studio, Emulator, etc.
What ended up being the issue is that I had to change from using Laravel Valet and use 'php artisan serve', then instead of localhost:8000, I had to use 10.0.2.2:8000. See link explaining in better detail: https://medium.com/@podcoder/connecting-flutter-application-to-localhost-a1022df63130
I gave up at some point and tried to download the full final code, but there were some other errors and I decided to learn more Flutter. I'll give it a try with your fix. Thank you
I faced the same problem, and after some search it turned out that in order for Android Studio to be able to connect to the localhost, it must use IP 10.0.2.2 and restart the emulator. The link I used and correctly worked like this http://10.0.2.2:8000/api/categories. 10.0.2.2 it's just like 127.0.0.1 in emulator.
I have been stuck on this lesson for a few hours trying to troubleshoot. I continue to get a "Something went wrong" message. I made the update to Uri so it's not that. I have restarted Android Studio, Emulator, etc.
What ended up being the issue is that I had to change from using Laravel Valet and use 'php artisan serve', then instead of localhost:8000, I had to use 10.0.2.2:8000. See link explaining in better detail: https://medium.com/@podcoder/connecting-flutter-application-to-localhost-a1022df63130
Thanks Ben for commenting it so others will learn. Not sure why it worked for me during shooting of this course, I don't remember this problem.
of course i think it looks like you are using an actual server with domain at this point in the tutorial so that may be why
I had a similar problem when using laravel valet. The problem was solved when I disabled https (valet unsecure).
I was keep getting "Something went wrong", then I printed the error from from snapshot and I have this error:
have you solve this error? I got it too.
I got it, the error is in the api response...
flutter must handle the api response which is : Example:
I gave up at some point and tried to download the full final code, but there were some other errors and I decided to learn more Flutter. I'll give it a try with your fix. Thank you
you can unwrap 'data' in your laravel api. Add this code in your AppServiceProvider.php
public function boot() { // Remove JSON bracket "data" JsonResource::withoutWrapping(); }
Or simply add this code in flutter: final data = jsonDecode(response.body); List categories = data['data'];
I recommend for following this video..
use this site [https://jsonplaceholder.typicode.com/] for api testing:
https://my-json-server.typicode.com/typicode/demo/posts
Hello all,
I faced the same problem, and after some search it turned out that in order for Android Studio to be able to connect to the localhost, it must use IP 10.0.2.2 and restart the emulator. The link I used and correctly worked like this http://10.0.2.2:8000/api/categories. 10.0.2.2 it's just like 127.0.0.1 in emulator.