All Projects → VB10 → vexana

VB10 / vexana

Licence: MIT license
Vexana is network manager project with dio.

Programming Languages

dart
5743 projects
C++
36643 projects - #6 most used programming language
CMake
9771 projects
ruby
36898 projects - #4 most used programming language
swift
15916 projects
HTML
75241 projects

Projects that are alternatives of or similar to vexana

flutter fish
仿闲鱼 flutter demo
Stars: ✭ 19 (-78.89%)
Mutual labels:  dio
Mung-Flutter
Although the project is small, it has all the internal organs, quick start Flutter actual combat!!!
Stars: ✭ 88 (-2.22%)
Mutual labels:  dio
Flutter Todos
📝 one day list app created by flutter!
Stars: ✭ 1,594 (+1671.11%)
Mutual labels:  dio
Flutter deer
🦌 Flutter 练习项目(包括集成测试、可访问性测试)。内含完整UI设计图,更贴近真实项目的练习。Flutter practice project. Includes a complete UI design and exercises that are closer to real projects.
Stars: ✭ 5,725 (+6261.11%)
Mutual labels:  dio
floggy
Customizable logger for dart and flutter applications.
Stars: ✭ 61 (-32.22%)
Mutual labels:  dio
Movie-Flutter
Movie App Flutter using Flutter BLoC, DIO, Retrofit, Sqflite
Stars: ✭ 36 (-60%)
Mutual labels:  dio
desafios-DIO
Desafios em C#, Java, JavaScript, Kotlin, Python e Ruby dos Bootcamps da Digital Innovation One
Stars: ✭ 140 (+55.56%)
Mutual labels:  dio
snake-js
Nostálgico jogo da 🐍 em JavaScript.
Stars: ✭ 24 (-73.33%)
Mutual labels:  dio
flutter read
A flutter project, 一款Flutter实战项目,已空安全适配,封装各种UI组件,网络组件以及使用peovider进行状态管理。
Stars: ✭ 51 (-43.33%)
Mutual labels:  dio
easyMarketFlutter
Flutter开发仿网易严选
Stars: ✭ 160 (+77.78%)
Mutual labels:  dio
flutter-netease
深度还原网易严选webApp,Flutter项目,接口为真实数据。项目已完善
Stars: ✭ 231 (+156.67%)
Mutual labels:  dio
curso-dio-intro-collections
Resolução dos exercícios propostos: CURSO INTRODUTÓRIO COLLECTIONS FRAMEWORK JAVA.
Stars: ✭ 422 (+368.89%)
Mutual labels:  dio

vexana

Vexana is easy to use network proccess with dio. You can do dynamic model parsing, base error model, timeout and many utility functions.

Vexana-Game

Getting Started 🔥

Let's talk about usage details.

Network Manager 😎

Have a lot of options: baseurl, logger, interceptors, base model etc.

If you want to manage your error model, you just declare your model so it's way getting the error model everywhere.

INetworkManager  networkManager = NetworkManage<Null or UserErrorModel>(isEnableLogger: true, errorModel: UserErrorModel(),
 options: BaseOptions(baseUrl: "https://jsonplaceholder.typicode.com/"));

Model Parse ⚔️

First, you have to provide the parse model, then the result model. (Result model could be a list, model or primitive)

final response =
await networkManager.send<Todo, List<Todo>>("/todos", parseModel: Todo(), method: RequestType.GET);

Base Headers 📍

You could be add key values to your every request directly.(add authhentication key)

networkManager.addBaseHeader(MapEntry(HttpHeaders.authorizationHeader, response.data?.first.title ?? ''));
// Clear singlhe header
networkManager.removeHeader('\${response.data?.first.id}');
// Clear all hader
networkManager.clearHeader();

Download File 📍

Download File Simple

You can download any file format like pdf, png or etc with progress indicator.

final response = await networkManager.downloadFileSimple('http://www.africau.edu/images/default/sample.pdf', (count, total) {
      print('${count}');
});

//Example: Image.memory(response.data)

Download File

You can download by specifying model and request type.

final response = await networkManager.downloadFile(
    'financial-report',
    (count, total) {
      print('${count}');
    },
    method: RequestType.POST,
    data: FileDownloadModel(),
);

HTTP Post Request with Request Body 🚀

The model found in the request body must extend the abstract class INetworkModel, as follows.

class TodoPostRequestData extends INetworkModel<TodoPostRequestData>

Then, since the model will have toJson and fromJson properties, you can create the object and pass it directly to the send method.

So, it is sufficient to send only the request body object into the send method. You don't need to use toJson.

final todoPostRequestBody = TodoPostRequestData();
final response =
await networkManager.send<Todo, List<Todo>>("/todosPost", parseModel: Todo(), method: RequestType.POST, data: todoPostRequestBody);

Cancel Request

You can implement cancel token when need to invoke your request during to complete.

  final cancelToken = CancelToken();
    networkManager
        .send<ReqResModel, ReqResModel>('/users?delay=5',
            parseModel: ReqResModel(), method: RequestType.GET, canceltoken: cancelToken)
        .catchError((err) {
      if (CancelToken.isCancel(err)) {
        print('Request canceled! ' + err.message);
      }
    });

    cancelToken.cancel('canceled');

    await Future.delayed(const Duration(seconds: 8));

Primitive Request 🌼

Sometimes we need to parse only primitive types for instance List, String, int etc. You can use this method.

//
[
  "en",
  "tr",
  "fr"
]
//
networkManager.sendPrimitive<List>("languages");

Network Model 🛒

You must wrap your model with INetworkModel so that, we understand model has toJson and fromJson methods.

class Todo extends INetworkModel<Todo>

Refresh Token ♻️

Many projects use authentication structure for mobile security (like a jwt). It could need to renew an older token when the token expires. This time provided a refresh token option, we can lock all requests until the token refresh process is complete.

Since i locked all requests, I am giving a new service instance.

INetworkManager  networkManager = NetworkManager(isEnableLogger: true, options: BaseOptions(baseUrl: "https://jsonplaceholder.typicode.com/"),
onRefreshFail: () {  //Navigate to login },
 onRefreshToken: (error, newService) async {
    <!-- Write your refresh token business -->
    <!-- Then update error.req.headers to new token -->
    return error;
});

Caching 🧲

You need to write a response model in the mobile device cache sometimes. It's here now. You can say expiration date and lay back 🙏

    await networkManager.send<Todo, List<Todo>>("/todos",
        parseModel: Todo(),
        expiration: Duration(seconds: 3),
        method: RequestType.GET);

You must declare a caching type. It has FileCache and SharedCache options now. NetworkManager(fileManager: LocalFile()); If you want more implementation details about the cache, you should read this article

Without Network connection 🧲

Especially, mobile device many times lost connection for many reasons so if you want to retry your request, you need to add this code and that's it. Your app user can be show bottom sheet dialog and they will be use this features only tree times because i added this rule.

    // First you must be initialize your context with NoNetwork class
    networkManager = NetworkManager(
      isEnableLogger: true,
      noNetwork: NoNetwork(context),
      options: BaseOptions(baseUrl: 'https://jsonplaceholder.typicode.com'),

      errorModelFromData: _errorModelFromData, //This is optional.
    );

    // If you want to create custom widget, you can add in no network class with callback function.
      networkManager = NetworkManager(
      isEnableLogger: true,
      noNetwork: NoNetwork(
        context,
        customNoNetwork: (onRetry) {
          // You have to call this retry method your custom widget
          return NoNetworkSample(onPressed: onRetry);
        },
      ),
      options: BaseOptions(baseUrl: 'https://jsonplaceholder.typicode.com'),

      //Example request
       final response = await networkManager.send<Post, List<Post>>('/posts',
        parseModel: Post(), method: RequestType.GET, isErrorDialog: true);

And result!!

alt

Error model handle

This point so important for many apps. Some business operation want to show any message or logic when user did a mistake like wrong password etc. You can manage very easily to error model for whole project with this usage.

INetworkManager  networkManager = NetworkManage<UserErrorModel>(isEnableLogger: true, errorModel: UserErrorModel(),
 options: BaseOptions(baseUrl: "https://jsonplaceholder.typicode.com/"));

 IResponseModel<List<Post>?, BaseErrorModel?> response =  networkManager.send<Post, List<Post>>('/posts',
        parseModel: Post(), method: RequestType.GET);
      <!-- Error.model came from your backend with your declaration -->
      showDialog(response.error?.model?.message)

    response

Tasks


  • Example project
  • Unit Test with json place holder
  • Unit Test with custom api
  • Handle network problem
  • Make a unit test all layers.
  • Cache Option
    • SQlite Support
    • Web Cache Support
  • Refresh Token Architecture
  • Usage Utility

License

License

2020 created for @VB10

Youtube Channel


Youtube

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].