passo_mobile_app/lib/utils/passo/post_request.dart

30 lines
665 B
Dart

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
// Reusable function to send a POST request
Future<http.Response?> postRequest({
required String url,
required Map<String, String> headers,
required Map<String, dynamic> body,
}) async {
try {
final response = await http.post(
Uri.parse(url),
headers: headers,
body: jsonEncode(body),
);
if (response.statusCode == 201) {
print('Post request successful');
} else {
print('Failed to post: ${response.statusCode}');
}
return response;
} catch (e) {
print('Error: $e');
return null;
}
}