Skip to content

Commit ccd2571

Browse files
committed
re-create client for each call
1 parent f87dfbd commit ccd2571

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/emailjs.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ class EmailJS {
2222
static String _host = 'api.emailjs.com';
2323

2424
/// HTTP Client specified in the [init] method
25-
static http.Client _httpClient = http.Client();
25+
static http.Client? _httpClient;
2626

2727
/// Global configuration for EmailJS
2828
///
2929
/// Sets globally the EmailJS [options]
3030
static void init(
3131
Options options, [
3232
String? host,
33-
http.Client? httpClient,
33+
http.Client? customHttpClient,
3434
]) {
3535
EmailJS._publicKey = options.publicKey;
3636
EmailJS._privateKey = options.privateKey;
3737
EmailJS._host = host ?? 'api.emailjs.com';
38-
EmailJS._httpClient = httpClient ?? http.Client();
38+
EmailJS._httpClient = customHttpClient;
3939
}
4040

4141
/// Sends the email through the [serviceID] using the ready-made [templateID].
@@ -63,9 +63,9 @@ class EmailJS {
6363
};
6464

6565
return await sendJSON(
66-
EmailJS._httpClient,
6766
Uri.https(EmailJS._host, 'api/v1.0/email/send'),
6867
json.encode(params),
68+
EmailJS._httpClient,
6969
);
7070
}
7171
}

lib/src/api/send_json.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import '../models/emailjs_response_status.dart';
33

44
/// sends JSON object via HTTP POST
55
Future<EmailJSResponseStatus> sendJSON(
6-
http.Client client, Uri uri, String data) async {
6+
Uri uri, String data, http.Client? customClient) async {
7+
8+
final client = customClient ?? http.Client();
9+
710
try {
8-
var response = await client.post(
11+
final response = await client.post(
912
uri,
1013
headers: {
1114
'Content-Type': 'application/json',

0 commit comments

Comments
 (0)