Last active
April 3, 2020 14:29
-
-
Save VB10/7b3535403b3f01fc9f5da6578eb75d62 to your computer and use it in GitHub Desktop.
Shoppi - Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:io'; | |
| import 'package:dio/dio.dart'; | |
| class BaseConfig { | |
| Dio dio; // with default Options | |
| String baseUrl; | |
| BaseConfig() { | |
| if (Platform.isIOS) { | |
| baseUrl = "http://localhost:4000/"; | |
| } else { | |
| baseUrl = "http://10.0.2.2:4000/"; | |
| } | |
| BaseOptions options = BaseOptions( | |
| baseUrl: baseUrl, | |
| connectTimeout: 5000, | |
| receiveTimeout: 3000, | |
| contentType: ContentType.json.value, | |
| ); | |
| dio = Dio(options); | |
| dio.interceptors | |
| .add(InterceptorsWrapper(onRequest: (RequestOptions options) async { | |
| return options; //continue | |
| }, onResponse: (Response response) async { | |
| return response; // continue | |
| }, onError: (DioError e) async { | |
| return e; //continue | |
| })); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class BaseModel<T> { | |
| Map<String, Object> toJson(); | |
| T fromJson(Map<String, Object> json); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:dio/dio.dart'; | |
| import 'package:flutter/cupertino.dart'; | |
| import 'base_config.dart'; | |
| import 'base_model.dart'; | |
| part './service-helper/service_helper.dart'; | |
| part './service-helper/service_request.dart'; | |
| class BaseNetwork { | |
| static BaseNetwork _instance; | |
| Dio _dio; | |
| static BaseNetwork get instance { | |
| if (_instance == null) { | |
| _instance = BaseNetwork._init(); | |
| } | |
| return _instance; | |
| } | |
| BaseNetwork._init() { | |
| _dio = BaseConfig().dio; | |
| } | |
| Future get<T extends BaseModel>( | |
| String path, { | |
| @required T responseModel, | |
| Function(int count, int total) onReceiveProgress, | |
| Map<String, dynamic> querys, | |
| }) async { | |
| return await _get<T>(path, | |
| responseModel: responseModel, onReceiveProgress: onReceiveProgress); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:shoppingapp/core/service/base_network.dart'; | |
| part './service-helper/service_constants.dart'; | |
| class BaseService { | |
| BaseNetwork service = BaseNetwork.instance; | |
| _RoutePath routePath = _RoutePath.instance; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment