mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 21:34:55 +00:00
create space model
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:syncrow_web/services/api/http_interceptor.dart';
|
||||
import 'package:syncrow_web/services/locator.dart';
|
||||
@ -42,22 +44,30 @@ class HTTPService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<T> post<T>(
|
||||
{required String path,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
Options? options,
|
||||
dynamic body,
|
||||
bool showServerMessage = true,
|
||||
required T Function(dynamic) expectedResponseModel}) async {
|
||||
Future<T> post<T>({
|
||||
required String path,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
Options? options,
|
||||
dynamic body,
|
||||
bool showServerMessage = true,
|
||||
required T Function(dynamic) expectedResponseModel,
|
||||
}) async {
|
||||
try {
|
||||
final bodyString = body is Map || body is List
|
||||
? jsonEncode(body)
|
||||
: body?.toString() ?? 'null';
|
||||
|
||||
print("POST Request: $path, Body: $bodyString, Query: $queryParameters");
|
||||
final response = await client.post(
|
||||
path,
|
||||
data: body,
|
||||
queryParameters: queryParameters,
|
||||
options: options,
|
||||
);
|
||||
print("POST Response: ${response.data.toString()}");
|
||||
return expectedResponseModel(response.data);
|
||||
} catch (error) {
|
||||
print("POST Error: $error");
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user