network_manager

A Network Manager package based on dio for easy REST API management

Getting Started

A Network Manager package based on dio for easy REST API management there is just some functionality written for using post and get api easily

Usage

it's suggested that initialize network manager at some entry point in app you can set BaseUrl, TimeOut, and some pre-written function that will be called on every request : onStartDefault, onEndDefault, onSuccessDefault, onFailedDefault.

    NetworkManagerMetaData.initialize(
      baseUrl: "http://google.com",
      successRules: (dynamic responseJson) => true;
      timeout: 30000,
      onStartDefault: () {
        print("Start");
      },
      onEndDefault: () {
        print("End");
      },
      onSuccessDefault: (){
        print("Success");
      },
      onFailedDefault: (){
        print("Failed");
      },
      timeout: 15000,
      successRules: (dynamic response)=>response["IsSuccess"],
      successMsgExtractor: (dynamic response) =>response["Message"],
      errorMsgExtractor: (dynamic error) =>error["Message"],
      headers: {
        'Content-Type': 'application/json',
        'Token': "Google Token",

      },
    );

Example

every where you want to make a request you can do as follows:

final Map<String,dynamic> req ={
      "Username": "test",
      "Password": "test",
    };

    NetworkManager networkManager = NetworkManager.instance(
      context: context,
      onSuccess: (context,response)=>print("OnSuccessCalled"),
      req: req,
      api: Apis.login
    );
    networkManager.requestPost();

Libraries

network_manager