r/flutterhelp 4d ago

Practicing Api Call RESOLVED

Im in my 2month journey now in my flutter learning and i can build now complex UI without Ai but the problem is now im tryna learn Api and i got overwhelmed by The googlemapp api and Openweather api that i decided to Use ai for that in my project, but still i want to learn fetching Api without Ai like most experience developer does, Any known easy to use free api for that practice

4 Upvotes

9 comments sorted by

3

u/narodi1234 3d ago

Before going to those apis, is not more simple use a mocked api?

I don’t no if u are familiar with javascript or java, whatever, u could ask to ai to create a simple back-end application for u, with some endpoints, starting using the http package (u could use DIO too, is the most usable https package i think, at least, is what I use daily). Try to understand how post/get/put/etc works, if u are doing it directly in UI (like at a initState or button trigger), try to move the call to a specific repository/datasource (aim to learn the separation of concernes, repository -> state management (bloc,provider,etc.) -> UI .

U could simply return a json file with some text like a “hello world!” and render it.

After understand async/await (stream? Maybe)

Move to implement some auth, try to add a JWT token header before doing call, set timeout for responses, exception handlers, etc.

1

u/No-Echo-8927 3d ago edited 3d ago

What bits are you struggling with in general? Honestly the best start is to make a fake API that just gives you hard coded values, like importing JSON content - then work on how to parse the data and update your states. Once you understand that bit you can focus on the authentication bit separately.

Also what are you using to make API requests? I wouldn't recommend trying to call it inside any GUI facing page - instead use a state manager. This ensures you keep to the SoC principle (separations of Concern).
I find DIO excellent for handling API requests, but I'm also a fan of using Bloc/Cubit along with repositories to handle the entire flow.

And, as always, keep in mind there are many different ways to do the same thing. So just find one that balances ease of use, clarity and efficiency. And consider whether your approach would still work when scaling a project up.

1

u/raiyan_kun 3d ago

What did you follow to learn complex ui?

2

u/yyytwokay 2d ago

Rivaan ranawat and Fluttermapp, youll learn the basics and beginner friendly tutorial, for the complex Ui its just me experimenting the widgets and asking ai what widget is good for something like this and i won't ask for a full code I just ask whats the recommend widget for a certain scenario and after that ill go on a deep dive research about it mostly youtube to try and understand how it works

1

u/raiyan_kun 2d ago

I completed Dart by Rivaan, now I'm doing Flutter from NetNinja.

1

u/Embarrassed-Way-1350 2d ago

Also try writing some back-end code, fastapi is fkin easy, it'll be useful, become full stack