Home > database >  Flutter http API calls
Flutter http API calls

Time:11-30

How can I setup a framework for API calling in flutter ?

Instead of just creating a api call function need to create a framework that can be used for multiple future projects

CodePudding user response:

If you are using Dio or any other libraries then the best way is to make a Dio helper class where you can change only the BASE_URL and will be globally used in all other classes after step by step you can add the not changeable things there.

I hope it helps

CodePudding user response:

You can make a separate project for API calls and models, this project will include the model classes and services for API calls. For API calls you can use retrofit or dio, whatever you want to use. This project will not include the UI, make the project by following command.

flutter create --template=package api_framework

Now you can include this framework project in many projects you want. Just add the path of this project in pubspec.yaml as following

dependencies:
  flutter:
    sdk: flutter

  api_fremework:
    path: ./api_framework

Now you will be able to call the API functions.

I hope it helps.

  • Related