0 purchases
apex flutter plugin
Apex Flutter Plugin #
A simple flutter plugin for ApexTeam fellas which supports http request management, request encryption, request cancellation, ... .
Getting Started #
Here we are! lets get started <3
Table of Contents #
Installation
Usage
Installation #
Send your gitlab id to [email protected] so I can add you to this project as a member.
Then make sure you have added this snippet in your pubspec.yaml under dependencies in the tree :
apex_flutter_plugin:
git:
url: https://gitlab.com/1839491/apexflutterlogin.git
path: apex_flutter_plugin
copied to clipboard
After that run flutter packages get and flutter packages upgrade to get the last version of the dependency.
Usage #
Code snippet for making a new request :
Note: Api is a singleton! so be careful with changing its config.
CancellationToken token = new CancellationToken(); //in case you need to cancel a ongoing request
Api.shared
.makeRequest(Request({"first":"second"}, method: Method.GET),
cancelToken: token)
.then((response) {
setState(() {
_text = response.body;
});
}).catchError((e) {
if (e is OperationCanceledError) {
print(e.toString());
} else if (e is TimeoutException) {
print(e.toString());
} else {
print(e.toString());
}
});
token.cancel("cancel this"); //whenever you need to cancel the request
copied to clipboard
You can also initialize the config of requests whenever you need just like this :
Api.shared.config = ApiConfig(
"https://jsonplaceholder.typicode.com/posts/1",
encrypt: false,
debugMode: true,
secretKey: Constants.CRYPTO_SECRET_KEY);
copied to clipboard
1. ApiConfig Inputs #
Every input parameters are optional except url which is positional.
Parameters
Data Type
Default Value
Note
url
String
-
-
encrypt
bool
false
true if you need encryption.
debugMode
bool
false
true if you need to see some log.
publicKey
String
null
RSA public key.
secretKey
String
null
AES secret key.
defaultParameters
Map<String, dynamic>
null
this will be added to every one of your requests.
2. Api makeRequest() method Inputs #
Every input parameters are optional except request which is positional.
Parameters
Data Type
Default Value
Note
request
Request
-
See how to create Request object.
timeLimit
Duration
-
If request future does not complete before timeLimit has passed, the onTimeout action is executed instead, and its result (whether it returns or throws) is used as the result of the returned future.
timeRetry
Duration
const Duration(milliseconds: 100)
-
onTimeOut
OnTimeOut
-
http OnTimeOut
cancelToken
CancellationToken
-
-
encoding
Encoding
-
The response body encoding. you can pass convert.Encoding.getByName("utf-8")
headers
Map<String, String>
-
The request headers
3. Request Inputs #
Parameters
Data Type
Default Value
params
Map<String, dynamic>
-
method
Method
Method.POST
4. Response Inputs #
Parameters
Data Type
Default Value
Note
result
Result
-
-
body
String
-
Server raw response body.
state
ResponseState
-
One of these ERROR, SUCCESS, UNEXPECTED
statusCode
num
-
Http request status code whichi is 400, 403, 500, ...
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.