Last active
April 26, 2020 10:57
-
-
Save IhwanID/0ed5aa3e06f91efc5e5de8751fa69167 to your computer and use it in GitHub Desktop.
api provider
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:pinjollist/model/company.dart'; | |
| import 'package:pinjollist/utils/logging_interceptors.dart'; | |
| class CompanyApiProvider { | |
| Dio get dio => _dio(); | |
| Dio _dio() { | |
| final options = BaseOptions( | |
| baseUrl: "https://pinjollist.now.sh/api/", | |
| connectTimeout: 5000, | |
| receiveTimeout: 3000, | |
| contentType: "application/json;charset=utf-8", | |
| ); | |
| var dio = Dio(options); | |
| dio.interceptors.add(LoggingInterceptors()); | |
| return dio; | |
| } | |
| Future<CompaniesResponse> getCompanies() async { | |
| try { | |
| Response response = await dio.get("companies"); | |
| return CompaniesResponse.fromJson(response.data); | |
| } catch (error, stacktrace) { | |
| throw Exception("Exception occured: $error stackTrace: $stacktrace"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment