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


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 :

      url: https://gitlab.com/1839491/apexflutterlogin.git
      path: apex_flutter_plugin

After that run flutter packages get and flutter packages upgrade to get the last version of the dependency.


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
                .makeRequest(Request({"first":"second"}, method: Method.GET),
                    cancelToken: token)
                .then((response) {
              setState(() {
                _text = response.body;
            }).catchError((e) {
              if (e is OperationCanceledError) {
              } else if (e is TimeoutException) {
              } else {
token.cancel("cancel this"); //whenever you need to cancel the request

You can also initialize the config of requests whenever you need just like this :

Api.shared.config = ApiConfig(
        encrypt: false,
        debugMode: true,
        secretKey: Constants.CRYPTO_SECRET_KEY);

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, ...