Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

First API Call - Categories List

Premium
7 min read

Since our categories are currently hard-coded into the screen directly, we cannot update them without updating the code. This is not ideal, so let's fetch the categories from the API instead.

In this lesson, we will:

  • Install HTTP package
  • Create our Category Model
  • Grant the necessary permissions to the API
  • Fetch the categories from the API

Let's dive in!


Installing HTTP Package

Installing packages in Flutter...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

AU
Artem Ushakov ✓ Link copied!

Ngrok is not really necessary in that case. While it is true, that localhost or 127.0.0.1 will point to the Android itself (since Android emulator is running in the VM), you can provide the 10.0.2.2:8080 in your Flutter app - in that case, it will point to the host's 127.0.0.1:8080. That will only work if your Laravel app is accessible at port 8080, of course. So in that scenario, what worked for me: Laravel in nginx with server_name _; and listen 8080; and in Flutter app: Uri.parse('http://10.0.2.2:8080/api/categories')

K
kornelkornecki ✓ Link copied!

If you use Mac or Windows you can use Herd and access your project locally like https://yourproject.test

M
Modestas ✓ Link copied!

While this is true, it is way easier to explain ngrok usage for most people :) It is just easier than having to deal with unreachable API endpoint due to some misconfiguration.

Also, the domain names specifically - did not work. So https://yourproject.test was unreachable when we were creating this course. That was why we added the ngrok usage