mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
Initialized Auth pages for future work
Implemented Login functionality
This commit is contained in:
@ -1,42 +1,32 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||
import 'package:syncrow_app/services/api/http_interceptor.dart';
|
||||
import 'package:syncrow_app/services/locator.dart';
|
||||
|
||||
import 'http_interceptor.dart';
|
||||
|
||||
class HTTPService {
|
||||
final Dio client = locator<Dio>();
|
||||
final navigatorKey = GlobalKey<NavigatorState>();
|
||||
late Dio client = serviceLocator.get<Dio>();
|
||||
|
||||
// final navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
String certificateString = "";
|
||||
|
||||
static Dio setupDioClient() {
|
||||
final client = Dio(
|
||||
Dio setupDioClient() {
|
||||
client = Dio(
|
||||
BaseOptions(
|
||||
// TODO add base url
|
||||
// baseUrl: URLConstants.baseURL,
|
||||
baseUrl: ApiEndpoints.baseUrl,
|
||||
receiveDataWhenStatusError: true,
|
||||
followRedirects: false,
|
||||
connectTimeout: const Duration(milliseconds: 60000),
|
||||
receiveTimeout: const Duration(milliseconds: 60000),
|
||||
connectTimeout: const Duration(minutes: 1),
|
||||
receiveTimeout: const Duration(minutes: 1),
|
||||
),
|
||||
);
|
||||
// (client.httpClientAdapter as IOHttpClientAdapter).createHttpClient = () {
|
||||
// client. = (X509Certificate cert, String host, int port) {
|
||||
// // TODO add SSL certificate
|
||||
// // if(cert.pem == certificateString){ // Verify the certificate
|
||||
// // return true;
|
||||
// // }
|
||||
// // return false;
|
||||
// return true;
|
||||
// };
|
||||
// return client;
|
||||
// };
|
||||
client.interceptors.add(locator<HTTPInterceptor>());
|
||||
|
||||
client.interceptors.add(serviceLocator.get<HTTPInterceptor>());
|
||||
return client;
|
||||
}
|
||||
|
||||
Future<T> getRequest<T>({
|
||||
Future<T> get<T>({
|
||||
required String path,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
required T Function(dynamic) expectedResponseModel,
|
||||
@ -55,7 +45,7 @@ class HTTPService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<T> postRequest<T>(
|
||||
Future<T> post<T>(
|
||||
{required String path,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
Options? options,
|
||||
@ -65,16 +55,18 @@ class HTTPService {
|
||||
try {
|
||||
final response = await client.post(path,
|
||||
data: body, queryParameters: queryParameters, options: options);
|
||||
print("post response is $response");
|
||||
debugPrint("status code is ${response.statusCode}");
|
||||
debugPrint("response data is ${response.data}");
|
||||
return expectedResponseModel(response.data);
|
||||
} catch (error) {
|
||||
debugPrint("******* Error");
|
||||
debugPrint("******* Error ********");
|
||||
debugPrint(error.toString());
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<T> patchRequest<T>(
|
||||
Future<T> patch<T>(
|
||||
{required String path,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
dynamic body,
|
||||
@ -94,7 +86,7 @@ class HTTPService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<T> downloadRequest<T>(
|
||||
Future<T> download<T>(
|
||||
{required String path,
|
||||
required String savePath,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
@ -118,4 +110,24 @@ class HTTPService {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
//delete
|
||||
Future<T> delete<T>({
|
||||
required String path,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
required T Function(dynamic) expectedResponseModel,
|
||||
bool showServerMessage = true,
|
||||
}) async {
|
||||
try {
|
||||
final response = await client.delete(
|
||||
path,
|
||||
queryParameters: queryParameters,
|
||||
);
|
||||
return expectedResponseModel(response.data);
|
||||
} catch (error) {
|
||||
debugPrint("******* Error");
|
||||
debugPrint(error.toString());
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user