• Stars
    star
    131
  • Rank 267,184 (Top 6 %)
  • Language
    Dart
  • License
    MIT License
  • Created over 3 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vexana is network manager project with dio.

vexana

Before Starting MY COUNTRY NEEDS TO HELP BECAUSE EARTHQUAKE 7.8 and 7.6 within some day!

help

Turkey has recently been struck by a devastating earthquake with a magnitude of 7.8. The impact has been widespread and many communities have been severely affected. In this difficult time, we are reaching out to ask for your support. Any donation, no matter how small, will help us provide much-needed aid to those affected by the earthquake. Your generosity will help provide shelter, food, and medical supplies to those in need. Your contribution will make a real difference in the lives of those affected by this disaster. Thank you for your kindness and support.

You can donate for AHBAP with this site AHBAP_DONATE

Vexana is easy to use network process 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 authentication key)

networkManager.addBaseHeader(MapEntry(HttpHeaders.authorizationHeader, response.data?.first.title ?? ''));
// Clear single header
networkManager.removeHeader('\${response.data?.first.id}');
// Clear all header
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
    • ISAAR Support
    • Web Cache Support
  • Refresh Token Architecture
  • Usage Utility
  • Readme Update

License

License

2020 created for @VB10

Youtube Channel


Youtube

Contributors

Made with contrib.rocks.

More Repositories

1

flutter-architecture-template

Flutter Architecture Complete App
Dart
533
star
2

Flutter-Full-Learn

End to end flutter series for zero to hero flutter devloper.( lang of videos is turkish)
Dart
232
star
3

flutter-ready-to-use-widgets

Kullanmaya hazir widget cozumleri -Ready to use widget solutions
Dart
149
star
4

Dart-Language-Full-Course

This repository created to learn deeply dart language with examples
Dart
102
star
5

vboverflow

Yes you can always ask to me anything but do you search problem or can you write any solutions?
94
star
6

flutter_firebase_full_news_app

Flutter Firebase Full App
Dart
82
star
7

sesimiduy

6 SUBAT DEPREMI UNUTMA!
Dart
76
star
8

kartal

very delicius extension library
Dart
69
star
9

shoppii

Shoppi is real time end to end mobile projects.
Dart
62
star
10

HealthoUI

This project ui example for flutter.
Dart
58
star
11

architecture_template_v2

"Flutter Architecture Template v2"
Dart
57
star
12

ecommerce_flutter_side

Ecommerce Flutter Project (Full)
Dart
57
star
13

WhatsApp-Chat

Whatsapp Chat Screen with Flutter
Dart
43
star
14

custom_localization

Localization with custom backend
Dart
32
star
15

flutter-abstract-theme-manager

Flutter Theme Manager with Abstract Factory Design
Dart
29
star
16

flutter_learn

Flutter Learn Series zero to end
Dart
25
star
17

CategoryShop

Listview has the category's tab options on Flutter.
Dart
24
star
18

use_case_flutter

Dart
22
star
19

ecommerce_backend

Ecommerce Backend Project for Flutter Apps
JavaScript
22
star
20

fluttermapsadvance

Flutter Maps Manager
Dart
21
star
21

state_managements_in_life

Dart
20
star
22

flutter-architecture-docs

HTML
18
star
23

advanced_search_flutter

Dart
18
star
24

Flutter-Cache-for-HTTP

Flutter HTTP network library cache architecture example.
Dart
17
star
25

cubit_login

Dart
16
star
26

fake_store_app

Fake Store Flutter App wih BLoC
C++
16
star
27

power-flutter-girls-travel-app

Dart
15
star
28

hwaflutter

@HardwareAndro Learn flutter series.
Dart
15
star
29

FlutterLearn

Flutter Eğitim Alıştırmaları
Dart
15
star
30

layered_architecture_flutter

Flutter layered architecture project
Dart
15
star
31

flightflutter

A based of Google maps. Flutter Flight project with OpenSky
Dart
14
star
32

Bomberman

Flutter bomberman game with flame
Dart
14
star
33

authentication_manager_flutter

Dart
13
star
34

snackoverflow

Snackoverflow App With SwiftUI
Swift
13
star
35

flutter_encrypt_cache

flutter encrypt and cache articles with pdf
Dart
13
star
36

HWASocial

End to End Social Media App for Xamarin forms
C#
12
star
37

mirro

Mirro is simple screen mirror project
C++
12
star
38

ecommerce-backend

Ecommerce backend for flutter project.
JavaScript
11
star
39

stack-over-help-flutter

Only Flutter problem solutions.(stack overflow or any request)
Dart
11
star
40

statemanagement

Flutter state management use case
Dart
11
star
41

hive_intro

Dart
11
star
42

XamarinFirebase

Database and Storage
Java
11
star
43

twittermobileclone

Twitter clone a flutter
Dart
11
star
44

make_flutter_apps_squads

How to build Flutter apps by every squad.
11
star
45

flutterresponsive

Dart
10
star
46

Best-Start-Flutter

Flutter starter best way
Dart
10
star
47

short_but_gold

Short but gold items for fltuter
C++
10
star
48

PDFKITAdvance

iOS Swift PDFKit - Curve Animations
Swift
10
star
49

fluttermvvmobx

Flutter MVVM and Mobx Tutorial
Dart
10
star
50

flutter_base_firebase_riverpod

Base Project with Firebase, Riverpod
Dart
10
star
51

flutter-generic-http

Generic Future request with http.
Dart
9
star
52

Devnot2020-Flutter

Flutter Education Devnot
Dart
9
star
53

how_to_atomic_app

Dart
9
star
54

custom_pdf_view

Dart
9
star
55

CleanJsonPlaceTableView

Clean Table View with Protocol Programming
Swift
8
star
56

tv-shows-while-working

Uzun çalışma saatlerini eğlenceli hale getirirken izlediklerim
8
star
57

Builder-Patterns-With-Dio

Dart
8
star
58

easy_cache_flutter

Dart
8
star
59

shoppibasket

Shopping Basket Architecture with Provider
Dart
8
star
60

SwiftUITutorials

This repository created by swift ui learn processes
Swift
8
star
61

VIPERHttpCats

Viper architecture to Swift
Swift
8
star
62

leviathan

UIKit for every project
Dart
7
star
63

ShoppingApp

Flutter shopping application. Design by @cuberto
Dart
7
star
64

hwablog

HardwareAndro blog application with Flutter.
Dart
6
star
65

fluttersql

Flutter sqlite sample. Project was created practices of strategy, abstract and clean code.
Dart
6
star
66

VB10

6
star
67

auto_flutter_route

C++
6
star
68

dartdev

Dart
6
star
69

AdvanceTodoAppSwift

This repo created for swift with storyboard
Swift
6
star
70

HTTP-Animal-Alphabetic-List

Flutter alphabetic list with http cat...
Dart
6
star
71

base_response_flutter

Dart
6
star
72

RickMortySwiftWithoutSB

Swift
6
star
73

sliver_pwers

Dart
6
star
74

fluttter_states

This repo have created for sample state management scenario.
Dart
6
star
75

vexana_inspector

Vexana Network Inspector
Dart
5
star
76

hackathon21

Dart
5
star
77

topselvi

Go backend project for you4
Go
5
star
78

usersbloc

Flutter bloc pattern infinity load page with null safety
Dart
5
star
79

twitch_best_practices

Flutter Refactoring from business
C++
5
star
80

multi_task_flutter

Dart
5
star
81

shoppin_architecture_samples

Dart
5
star
82

todo

Flutter Todo Application
Dart
5
star
83

flutterfire

Hwa Firebase Project
Dart
4
star
84

Atomic-Design-with-Stateless

A flutter atomic design and stateless widget learn series.
Dart
4
star
85

best_start_way_2

Dart
4
star
86

SwiftGoals

Swift Language starter project
Swift
4
star
87

izmir_sto

C++
4
star
88

great_way

Dart
4
star
89

flutter_observer_pattern

Dart
4
star
90

vbt_learn_2022

C++
4
star
91

MoviesSwiftUI

Movie db project created for swiftui
Swift
4
star
92

only_code

only_code
C++
4
star
93

IOSCoreSeriesSB

Swift learn series with ios project (story board)
Swift
4
star
94

Plexus-Backend

Plexus a learn mobile backend project with Nodejs.
JavaScript
3
star
95

findo

Findo is a simple textfield. It provide to debounce options while using write anythink.
Dart
3
star
96

blocarchitecturesample

Dart
3
star
97

vbtlearn

Dart
3
star
98

circles

Dart
3
star
99

HTTPDogsSwiftUI

Dogs HTTP Status MVVM App with Swift UI
Swift
3
star
100

Chat-App-Xamarin-Firebase

Java
3
star