Getting started
This package is used to make requests to an API. It is based on the http package.
Supports the following request types: GET
, POST
, PUT
, DELETE
.
Types of request bodies supported: JSON
, x-www-form-urlencoded
, fromData
.
Supports platform compilation for:
x
Androidx
iOSx
Webx
Windowsx
Linux
Exception mode debug ios:
The environment variables in debug mode do not run on emulators at the moment.
Using environment variables
- In the api-key.json.tpl file, make a copy and remove the .tpl extension.
- Add the required variables to the api-key.json file.
# Ejemplo:
{
"API_URL": "https://example.com",
"API_URL_PRODUCTION":"example.com",
"PROTOCOL":"https",
"DEBUG": true
},
Compilation Method
- If you are using Visual Studio Code, edit the .vscode/launch.json file. If it does not exist, create it with the following content:
{
"version": "0.2.0",
"configurations": [
{
"name": "app",
"request": "launch",
"type": "dart",
"args": ["--dart-define-from-file","api-key.json"]
},
{
"name": "app (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile",
"args": ["--dart-define-from-file","api-key.json"]
},
{
"name": "app (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release",
"args": ["--dart-define-from-file","api-key.json"]
},
]
},
- Afterward, you can compile normally with F5 in debug, profile, or release mode.
Usage
# If you define the URLs with the https or http prefix, the PROTOCOL environment variable will not be relevant.
{
"API_URL": "https://example.com",
"API_URL_PRODUCTION": "https://example.com",
"PROTOCOL":"https",
"DEBUG": true
},
o
# If you define the URLs without the prefix, the PROTOCOL environment variable will be relevant.
{
"API_URL": "localhost:4000"
"API_URL_PRODUCTION": "localhost:4000"
"PROTOCOL": "http"
"DEBUG": true
}
Note 1:
PROTOCOL
: This variable is used to define the connection protocol. By default, it ishttps
, but if you wish to change it tohttp
, you should modify the value tohttp
and add theAPI_URL
variable with the connection domain.
Note 2:
DEBUG
: By default, it is set totrue
, which will always make requests using thehttps
protocol. You can also connect to the production domain by settingDEBUG
tofalse
and providing theAPI_URL_PRODUCTION
environment variable.
Note 3:
API_URL
andAPI_URL_PRODUCTION
: These variables are used to define the connection domain. If you use a URL with thehttps
orhttp
prefix, these variables take precedence over thePROTOCOL
environment variable. If you use the URLexample.com
, the protocol defined in thePROTOCOL
environment variable will be used.
Commands for Different Compilation Types:
Before compiling, make sure that the DEBUG mode is set as desired. Before performing different compilations, it is recommended to run the following command:
flutter clean
flutter pub get
Compilation in release mode for APK or app bundle:
flutter build apk --split-per-abi --dart-define-from-file=api-key.json
flutter build appbundle --dart-define-from-file=api-key.json
Compilation for iOS:
flutter build ipa --dart-define-from-file=api-key.json
Running the following command will generate the .ipa file for uploading to the App Store:
open ./build/ios/archive/Runner.xcarchive
Compilation for the web:
flutter build web --dart-define-from-file=api-key.json
Or, if a base-href is required:
flutter build web --base-href "/" --dart-define-from-file=api-key.json
Contribution
Of course the project is open source, and you can contribute to it repository link.
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.