network_manager 0.0.70
network_manager: ^0.0.70 copied to clipboard

Flutter Android iOS

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

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.

      initializeNetworkManager() {
        /// initialize network manager
        NetworkManagerMetaData.initialize(
            baseUrl: "http://example.com",
            timeout: 30000,
            token: token,
            headers: {
              'Content-Type': "application/json",
            },
            onStartDefault: () {
              print("Start");
            },
            onEndDefault: () {
              print("End");
            },
            onSuccessDefault: () {
              print("Success");
            },
            onFailedDefault: () {
              print("Failed");
            },
            successRules: (result) {
              return (result["Status"] ?? -1) > 0;
            },
            tokenExpireRules: (resultJson) {
              return (resultJson["Status"] == -999);
            },
            onTokenExpire: (retryFunction) {
              print("Failed");
              // can call retry function
            },
            useFancyDialog: true,
            errorMsgExtractor: (result) {
              return result["Message"] ?? "Unknown Error";
            });
      }

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();
2
likes
90
pub points
49%
popularity

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

Homepage

Documentation

API reference

Uploader

s.ma.bakhshayesh@gmail.com

License

MIT (LICENSE)

Dependencies

dio, flutter, handy_ui_kit

More

Packages that depend on network_manager